@stacks/storage 3.5.0-beta.3 → 3.5.1-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacks/storage",
3
- "version": "3.5.0-beta.3",
3
+ "version": "3.5.1-beta.1",
4
4
  "description": "Stacks storage library",
5
5
  "author": "yknl <yukanliao@gmail.com>",
6
6
  "homepage": "https://blockstack.org",
@@ -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": "803065f20e4ec1aa02836b4179447a540288d0ec"
65
+ "gitHead": "191f4a492cbf6d3b20462dc9d935155c2bed330a"
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 = ecPairToAddress(
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 = ecPairToAddress(challengeSigner);
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
- import { lookupProfile, NAME_LOOKUP_PATH, UserSession } from '@stacks/auth';
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
- 'Failed to get gaia address for verification of: ' + `${path}`
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
- 'Failed to get gaia address for verification of: ' + `${path}`
410
+ `Failed to get gaia address for verification of: ${path}`
415
411
  );
416
412
  }
417
413
  let sigObject;