@stacks/storage 3.5.1-beta.0 → 3.5.1-beta.3
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 +6 -9
- 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 +24 -27
- package/dist/hub.js.map +1 -1
- package/dist/index.js +5 -1
- 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 +14 -19
- package/src/storage.ts +20 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacks/storage",
|
|
3
|
-
"version": "3.5.1-beta.
|
|
3
|
+
"version": "3.5.1-beta.3",
|
|
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.3.0",
|
|
36
|
+
"@stacks/common": "^3.3.0",
|
|
37
|
+
"@stacks/encryption": "^3.3.0",
|
|
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": "a49e8ad989c9172bfa4a0cf73d24e75fcc35b2b9"
|
|
66
66
|
}
|
package/src/hub.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
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
|
-
|
|
12
1
|
import {
|
|
13
2
|
BadPathError,
|
|
3
|
+
Buffer,
|
|
14
4
|
ConflictError,
|
|
15
5
|
DoesNotExist,
|
|
16
6
|
fetchPrivate,
|
|
@@ -22,6 +12,16 @@ import {
|
|
|
22
12
|
PreconditionFailedError,
|
|
23
13
|
ValidationError,
|
|
24
14
|
} 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,10 +149,8 @@ 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' : ''));
|
|
153
152
|
const digest = hashSha256Sync(Buffer.from(challengeText));
|
|
154
|
-
|
|
155
|
-
const signatureBuffer = signer.sign(digest);
|
|
153
|
+
const signatureBuffer = ecSign(digest, compressPrivateKey(signerKeyHex));
|
|
156
154
|
const signatureWithHash = script.signature.encode(signatureBuffer, Transaction.SIGHASH_NONE);
|
|
157
155
|
|
|
158
156
|
// We only want the DER encoding so remove the sighash version byte at the end.
|
|
@@ -221,9 +219,7 @@ export async function connectToGaiaHub(
|
|
|
221
219
|
const hubInfo = await response.json();
|
|
222
220
|
const readURL = hubInfo.read_url_prefix;
|
|
223
221
|
const token = makeV1GaiaAuthToken(hubInfo, challengeSignerHex, gaiaHubUrl, associationToken);
|
|
224
|
-
const address =
|
|
225
|
-
hexStringToECPair(challengeSignerHex + (challengeSignerHex.length === 64 ? '01' : ''))
|
|
226
|
-
);
|
|
222
|
+
const address = publicKeyToAddress(getPublicKeyFromPrivate(challengeSignerHex));
|
|
227
223
|
return {
|
|
228
224
|
url_prefix: readURL,
|
|
229
225
|
max_file_upload_size_megabytes: hubInfo.max_file_upload_size_megabytes,
|
|
@@ -241,12 +237,11 @@ export async function connectToGaiaHub(
|
|
|
241
237
|
* @ignore
|
|
242
238
|
*/
|
|
243
239
|
export async function getBucketUrl(gaiaHubUrl: string, appPrivateKey: string): Promise<string> {
|
|
244
|
-
const challengeSigner = ECPair.fromPrivateKey(Buffer.from(appPrivateKey, 'hex'));
|
|
245
240
|
const response = await fetchPrivate(`${gaiaHubUrl}/hub_info`);
|
|
246
241
|
const responseText = await response.text();
|
|
247
242
|
const responseJSON = JSON.parse(responseText);
|
|
248
243
|
const readURL = responseJSON.read_url_prefix;
|
|
249
|
-
const address =
|
|
244
|
+
const address = publicKeyToAddress(getPublicKeyFromPrivate(appPrivateKey));
|
|
250
245
|
const bucketUrl = `${readURL}${address}/`;
|
|
251
246
|
return bucketUrl;
|
|
252
247
|
}
|
package/src/storage.ts
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import { Buffer } from '@stacks/common';
|
|
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
|
-
|
|
3
|
+
import { lookupProfile, NAME_LOOKUP_PATH, UserSession } from '@stacks/auth';
|
|
22
4
|
import {
|
|
23
5
|
BLOCKSTACK_DEFAULT_GAIA_HUB_URL,
|
|
24
6
|
DoesNotExist,
|
|
@@ -30,10 +12,24 @@ import {
|
|
|
30
12
|
PayloadTooLargeError,
|
|
31
13
|
SignatureVerificationError,
|
|
32
14
|
} from '@stacks/common';
|
|
33
|
-
|
|
15
|
+
import {
|
|
16
|
+
eciesGetJsonStringLength,
|
|
17
|
+
EncryptionOptions,
|
|
18
|
+
getPublicKeyFromPrivate,
|
|
19
|
+
publicKeyToAddress,
|
|
20
|
+
signECDSA,
|
|
21
|
+
verifyECDSA,
|
|
22
|
+
} from '@stacks/encryption';
|
|
34
23
|
import { FileContentLoader } from './fileContentLoader';
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
import {
|
|
25
|
+
connectToGaiaHub,
|
|
26
|
+
deleteFromGaiaHub,
|
|
27
|
+
GaiaHubConfig,
|
|
28
|
+
getBlockstackErrorFromResponse,
|
|
29
|
+
getBucketUrl,
|
|
30
|
+
getFullReadUrl,
|
|
31
|
+
uploadToGaiaHub,
|
|
32
|
+
} from './hub';
|
|
37
33
|
|
|
38
34
|
/**
|
|
39
35
|
* Specify a valid MIME type, encryption options, and whether to sign the [[UserSession.putFile]].
|
|
@@ -331,7 +327,7 @@ export class Storage {
|
|
|
331
327
|
}
|
|
332
328
|
if (!gaiaAddress) {
|
|
333
329
|
throw new SignatureVerificationError(
|
|
334
|
-
|
|
330
|
+
`Failed to get gaia address for verification of: ${path}`
|
|
335
331
|
);
|
|
336
332
|
}
|
|
337
333
|
if (!signatureContents || typeof signatureContents !== 'string') {
|
|
@@ -411,7 +407,7 @@ export class Storage {
|
|
|
411
407
|
}
|
|
412
408
|
if (!address) {
|
|
413
409
|
throw new SignatureVerificationError(
|
|
414
|
-
|
|
410
|
+
`Failed to get gaia address for verification of: ${path}`
|
|
415
411
|
);
|
|
416
412
|
}
|
|
417
413
|
let sigObject;
|