mirror of
https://github.com/zhigang1992/connect.git
synced 2026-04-29 18:05:45 +08:00
fix(keychain): use correct filepath when writing profiles
This commit is contained in:
committed by
Hank Stoever
parent
93f9cd7a46
commit
fa8098ae13
@@ -69,7 +69,8 @@ export class Identity {
|
||||
profile.apps = {};
|
||||
}
|
||||
const challengeSigner = ECPair.fromPrivateKey(Buffer.from(appPrivateKey, 'hex'));
|
||||
const storageUrl = `${hubInfo.read_url_prefix}${ecPairToAddress(challengeSigner)}/`;
|
||||
const address = ecPairToAddress(challengeSigner);
|
||||
const storageUrl = `${hubInfo.read_url_prefix}${address}/`;
|
||||
profile.apps[appDomain] = storageUrl;
|
||||
if (!profile.appsMeta) {
|
||||
profile.appsMeta = {};
|
||||
@@ -83,7 +84,7 @@ export class Identity {
|
||||
privateKey: this.keyPair.key,
|
||||
gaiaHubUrl: gaiaUrl,
|
||||
});
|
||||
const filePath = new URL(profileUrl).pathname.substr(1);
|
||||
const filePath = this.gaiaReadUrlToWritePath(profileUrl, hubInfo.read_url_prefix, address);
|
||||
await signAndUploadProfile({
|
||||
profile,
|
||||
identity: this,
|
||||
@@ -137,6 +138,10 @@ export class Identity {
|
||||
return `${gaiaUrl}${this.address}/profile.json`;
|
||||
}
|
||||
|
||||
gaiaReadUrlToWritePath(gaiaReadUrl: string, read_url_prefix: string, address: string): string {
|
||||
return gaiaReadUrl.substr(`${read_url_prefix}${address}/`.length);
|
||||
}
|
||||
|
||||
async fetchNames() {
|
||||
const getNamesUrl = `https://core.blockstack.org/v1/addresses/bitcoin/${this.address}`;
|
||||
const res = await fetch(getNamesUrl);
|
||||
|
||||
@@ -105,6 +105,27 @@ test('can get a profile URL from a zone file', async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('gets correct profile write URL', async () => {
|
||||
const identity = await getIdentity();
|
||||
const gaiaUrl = 'https://gaia.blockstack.org/hub/';
|
||||
|
||||
expect(
|
||||
await identity.gaiaReadUrlToWritePath(
|
||||
'https://gaia.blockstack.org/hub/1JeTQ5cQjsD57YGcsVFhwT7iuQUXJR6BSk/profile.json',
|
||||
'https://gaia.blockstack.org/hub/',
|
||||
'1JeTQ5cQjsD57YGcsVFhwT7iuQUXJR6BSk'
|
||||
)
|
||||
).toEqual('profile.json');
|
||||
|
||||
expect(
|
||||
await identity.gaiaReadUrlToWritePath(
|
||||
'https://gaia.blockstack.org/hub/1J3PUxY5uDShUnHRrMyU6yKtoHEUPhKULs/0/myprofile',
|
||||
'https://gaia.blockstack.org/hub/',
|
||||
'1JeTQ5cQjsD57YGcsVFhwT7iuQUXJR6BSk'
|
||||
)
|
||||
).toEqual('0/myprofile');
|
||||
});
|
||||
|
||||
describe('refresh', () => {
|
||||
test('can fetch names for an identity', async () => {
|
||||
const identity = await getIdentity();
|
||||
|
||||
Reference in New Issue
Block a user