@stacks/storage 3.5.1-beta.4 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/hub.js +9 -6
- package/dist/esm/hub.js.map +1 -1
- package/dist/esm/storage.d.ts +2 -2
- package/dist/esm/storage.js +5 -5
- package/dist/esm/storage.js.map +1 -1
- package/dist/hub.js +27 -24
- package/dist/hub.js.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/polyfill/index.js +3 -3
- package/dist/storage.d.ts +2 -2
- package/dist/storage.js +35 -35
- package/dist/storage.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.LICENSE.txt +2 -2
- package/dist/umd/index.js.map +1 -1
- package/package.json +5 -5
- package/src/hub.ts +19 -14
- package/src/storage.ts +24 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacks/storage",
|
|
3
|
-
"version": "3.5.1
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "Stacks storage library",
|
|
5
5
|
"author": "yknl <yukanliao@gmail.com>",
|
|
6
6
|
"homepage": "https://blockstack.org",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"url": "https://github.com/blockstack/blockstack.js/issues"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@stacks/auth": "^3.
|
|
36
|
-
"@stacks/common": "^3.
|
|
37
|
-
"@stacks/encryption": "^3.
|
|
35
|
+
"@stacks/auth": "^3.5.1",
|
|
36
|
+
"@stacks/common": "^3.5.1",
|
|
37
|
+
"@stacks/encryption": "^3.5.1",
|
|
38
38
|
"bitcoinjs-lib": "^5.2.0",
|
|
39
39
|
"jsontokens": "^3.0.0"
|
|
40
40
|
},
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"browser": "dist/polyfill/index.js",
|
|
63
63
|
"umd:main": "dist/umd/index.js",
|
|
64
64
|
"unpkg": "dist/umd/index.js",
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "7a0fbb9b2bf7ba7e842c1eecaf69b052fc6b5df1"
|
|
66
66
|
}
|
package/src/hub.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
import { Buffer } from '@stacks/common';
|
|
2
|
+
import { ECPair, script, Transaction } from 'bitcoinjs-lib';
|
|
3
|
+
import { TokenSigner } from 'jsontokens';
|
|
4
|
+
import {
|
|
5
|
+
ecPairToAddress,
|
|
6
|
+
getPublicKeyFromPrivate,
|
|
7
|
+
hashSha256Sync,
|
|
8
|
+
hexStringToECPair,
|
|
9
|
+
randomBytes,
|
|
10
|
+
} from '@stacks/encryption';
|
|
11
|
+
|
|
1
12
|
import {
|
|
2
13
|
BadPathError,
|
|
3
|
-
Buffer,
|
|
4
14
|
ConflictError,
|
|
5
15
|
DoesNotExist,
|
|
6
16
|
fetchPrivate,
|
|
@@ -12,16 +22,6 @@ import {
|
|
|
12
22
|
PreconditionFailedError,
|
|
13
23
|
ValidationError,
|
|
14
24
|
} from '@stacks/common';
|
|
15
|
-
import {
|
|
16
|
-
compressPrivateKey,
|
|
17
|
-
ecSign,
|
|
18
|
-
getPublicKeyFromPrivate,
|
|
19
|
-
hashSha256Sync,
|
|
20
|
-
publicKeyToAddress,
|
|
21
|
-
randomBytes,
|
|
22
|
-
} from '@stacks/encryption';
|
|
23
|
-
import { script, Transaction } from 'bitcoinjs-lib';
|
|
24
|
-
import { TokenSigner } from 'jsontokens';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* @ignore
|
|
@@ -149,8 +149,10 @@ function makeLegacyAuthToken(challengeText: string, signerKeyHex: string): strin
|
|
|
149
149
|
throw new Error('Failed in parsing legacy challenge text from the gaia hub.');
|
|
150
150
|
}
|
|
151
151
|
if (parsedChallenge[0] === 'gaiahub' && parsedChallenge[3] === 'blockstack_storage_please_sign') {
|
|
152
|
+
const signer = hexStringToECPair(signerKeyHex + (signerKeyHex.length === 64 ? '01' : ''));
|
|
152
153
|
const digest = hashSha256Sync(Buffer.from(challengeText));
|
|
153
|
-
|
|
154
|
+
|
|
155
|
+
const signatureBuffer = signer.sign(digest);
|
|
154
156
|
const signatureWithHash = script.signature.encode(signatureBuffer, Transaction.SIGHASH_NONE);
|
|
155
157
|
|
|
156
158
|
// We only want the DER encoding so remove the sighash version byte at the end.
|
|
@@ -219,7 +221,9 @@ export async function connectToGaiaHub(
|
|
|
219
221
|
const hubInfo = await response.json();
|
|
220
222
|
const readURL = hubInfo.read_url_prefix;
|
|
221
223
|
const token = makeV1GaiaAuthToken(hubInfo, challengeSignerHex, gaiaHubUrl, associationToken);
|
|
222
|
-
const address =
|
|
224
|
+
const address = ecPairToAddress(
|
|
225
|
+
hexStringToECPair(challengeSignerHex + (challengeSignerHex.length === 64 ? '01' : ''))
|
|
226
|
+
);
|
|
223
227
|
return {
|
|
224
228
|
url_prefix: readURL,
|
|
225
229
|
max_file_upload_size_megabytes: hubInfo.max_file_upload_size_megabytes,
|
|
@@ -237,11 +241,12 @@ export async function connectToGaiaHub(
|
|
|
237
241
|
* @ignore
|
|
238
242
|
*/
|
|
239
243
|
export async function getBucketUrl(gaiaHubUrl: string, appPrivateKey: string): Promise<string> {
|
|
244
|
+
const challengeSigner = ECPair.fromPrivateKey(Buffer.from(appPrivateKey, 'hex'));
|
|
240
245
|
const response = await fetchPrivate(`${gaiaHubUrl}/hub_info`);
|
|
241
246
|
const responseText = await response.text();
|
|
242
247
|
const responseJSON = JSON.parse(responseText);
|
|
243
248
|
const readURL = responseJSON.read_url_prefix;
|
|
244
|
-
const address =
|
|
249
|
+
const address = ecPairToAddress(challengeSigner);
|
|
245
250
|
const bucketUrl = `${readURL}${address}/`;
|
|
246
251
|
return bucketUrl;
|
|
247
252
|
}
|
package/src/storage.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import { Buffer } from '@stacks/common';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
connectToGaiaHub,
|
|
5
|
+
deleteFromGaiaHub,
|
|
6
|
+
GaiaHubConfig,
|
|
7
|
+
getBlockstackErrorFromResponse,
|
|
8
|
+
getBucketUrl,
|
|
9
|
+
getFullReadUrl,
|
|
10
|
+
uploadToGaiaHub,
|
|
11
|
+
} from './hub';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
eciesGetJsonStringLength,
|
|
15
|
+
EncryptionOptions,
|
|
16
|
+
getPublicKeyFromPrivate,
|
|
17
|
+
publicKeyToAddress,
|
|
18
|
+
signECDSA,
|
|
19
|
+
verifyECDSA,
|
|
20
|
+
} from '@stacks/encryption';
|
|
21
|
+
|
|
4
22
|
import {
|
|
5
23
|
BLOCKSTACK_DEFAULT_GAIA_HUB_URL,
|
|
6
24
|
DoesNotExist,
|
|
@@ -12,24 +30,10 @@ import {
|
|
|
12
30
|
PayloadTooLargeError,
|
|
13
31
|
SignatureVerificationError,
|
|
14
32
|
} from '@stacks/common';
|
|
15
|
-
|
|
16
|
-
eciesGetJsonStringLength,
|
|
17
|
-
EncryptionOptions,
|
|
18
|
-
getPublicKeyFromPrivate,
|
|
19
|
-
publicKeyToAddress,
|
|
20
|
-
signECDSA,
|
|
21
|
-
verifyECDSA,
|
|
22
|
-
} from '@stacks/encryption';
|
|
33
|
+
|
|
23
34
|
import { FileContentLoader } from './fileContentLoader';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
deleteFromGaiaHub,
|
|
27
|
-
GaiaHubConfig,
|
|
28
|
-
getBlockstackErrorFromResponse,
|
|
29
|
-
getBucketUrl,
|
|
30
|
-
getFullReadUrl,
|
|
31
|
-
uploadToGaiaHub,
|
|
32
|
-
} from './hub';
|
|
35
|
+
|
|
36
|
+
import { lookupProfile, NAME_LOOKUP_PATH, UserSession } from '@stacks/auth';
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
39
|
* Specify a valid MIME type, encryption options, and whether to sign the [[UserSession.putFile]].
|
|
@@ -327,7 +331,7 @@ export class Storage {
|
|
|
327
331
|
}
|
|
328
332
|
if (!gaiaAddress) {
|
|
329
333
|
throw new SignatureVerificationError(
|
|
330
|
-
|
|
334
|
+
'Failed to get gaia address for verification of: ' + `${path}`
|
|
331
335
|
);
|
|
332
336
|
}
|
|
333
337
|
if (!signatureContents || typeof signatureContents !== 'string') {
|
|
@@ -407,7 +411,7 @@ export class Storage {
|
|
|
407
411
|
}
|
|
408
412
|
if (!address) {
|
|
409
413
|
throw new SignatureVerificationError(
|
|
410
|
-
|
|
414
|
+
'Failed to get gaia address for verification of: ' + `${path}`
|
|
411
415
|
);
|
|
412
416
|
}
|
|
413
417
|
let sigObject;
|