@novasamatech/statement-store 0.7.5-4 → 0.7.6

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.
Files changed (2) hide show
  1. package/dist/crypto.js +14 -3
  2. package/package.json +2 -2
package/dist/crypto.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { blake2b } from '@noble/hashes/blake2.js';
2
2
  import { entropyToMiniSecret } from '@polkadot-labs/hdkd-helpers';
3
3
  import { HDKD as sr25519HDKD, getPublicKey as sr25519GetPublicKey, secretFromSeed as sr25519SecretFromSeed, sign as sr25519Sign, verify as sr25519Verify, } from '@scure/sr25519';
4
- import { Bytes, str } from 'scale-ts';
4
+ import { Bytes, str, u64 } from 'scale-ts';
5
5
  export function BrandedBytesCodec(length) {
6
6
  return Bytes(length);
7
7
  }
@@ -26,9 +26,20 @@ function parseDerivations(derivationsStr) {
26
26
  }
27
27
  return derivations;
28
28
  }
29
+ const JUNCTION_ID_LEN = 32;
30
+ const NUMERIC_JUNCTION_RE = /^\d+$/;
31
+ // Substrate `DeriveJunction` chain-code encoding (sp_core::crypto::DeriveJunction):
32
+ // - if the junction parses as an unsigned integer, SCALE-encode as u64 LE
33
+ // - otherwise SCALE-encode as a string (compact length + UTF-8)
34
+ // - if the encoded payload is longer than 32 bytes, replace it with blake2-256(payload)
35
+ // - left-pad / truncate the result into a 32-byte chain code
29
36
  function createChainCode(derivation) {
30
- const chainCode = new Uint8Array(32);
31
- chainCode.set(str.enc(derivation));
37
+ const encoded = NUMERIC_JUNCTION_RE.test(derivation) ? u64.enc(BigInt(derivation)) : str.enc(derivation);
38
+ if (encoded.length > JUNCTION_ID_LEN) {
39
+ return blake2b(encoded, { dkLen: JUNCTION_ID_LEN });
40
+ }
41
+ const chainCode = new Uint8Array(JUNCTION_ID_LEN);
42
+ chainCode.set(encoded);
32
43
  return chainCode;
33
44
  }
34
45
  // statement store key pair
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/statement-store",
3
3
  "type": "module",
4
- "version": "0.7.5-4",
4
+ "version": "0.7.6",
5
5
  "description": "Statement store integration",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "README.md"
26
26
  ],
27
27
  "dependencies": {
28
- "@novasamatech/scale": "0.7.5-4",
28
+ "@novasamatech/scale": "0.7.6",
29
29
  "@novasamatech/sdk-statement": "^0.6.0",
30
30
  "@polkadot-api/substrate-bindings": "^0.20.1",
31
31
  "@polkadot-api/substrate-client": "^0.7.0",