@xyo-network/account-model 6.0.6 → 6.0.8

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.
@@ -1,9 +1,5 @@
1
1
  export type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65';
2
- export declare const AccountAlgorithmPrefix: {
3
- readonly secp256k1: null;
4
- readonly 'ml-dsa-65': "qr1";
5
- };
2
+ export declare const AccountAlgorithmHrp: Partial<Record<AccountAlgorithm, string>>;
3
+ export declare function hrpForAlgorithm(algorithm: AccountAlgorithm): string | undefined;
6
4
  export declare function algorithmFromAddress(address: string): AccountAlgorithm;
7
- export declare function stripAddressPrefix(address: string): string;
8
- export declare function prefixForAlgorithm(algorithm: AccountAlgorithm): string;
9
5
  //# sourceMappingURL=Algorithm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Algorithm.d.ts","sourceRoot":"","sources":["../../src/Algorithm.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,CAAA;AAExD,eAAO,MAAM,sBAAsB;;;CAGyB,CAAA;AAE5D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAOtE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,CAGtE"}
1
+ {"version":3,"file":"Algorithm.d.ts","sourceRoot":"","sources":["../../src/Algorithm.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,CAAA;AAUxD,eAAO,MAAM,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAA2C,CAAA;AAMrH,wBAAgB,eAAe,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAE/E;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAStE"}
@@ -1 +1 @@
1
- {"version":3,"file":"addressTo20Bytes.d.ts","sourceRoot":"","sources":["../../src/addressTo20Bytes.ts"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAEjE"}
1
+ {"version":3,"file":"addressTo20Bytes.d.ts","sourceRoot":"","sources":["../../src/addressTo20Bytes.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAIjE"}
@@ -29,31 +29,32 @@ var isAccountInstance = (account) => {
29
29
 
30
30
  // src/addressTo20Bytes.ts
31
31
  import { toUint8Array } from "@xylabs/sdk-js";
32
+ import { tryDecodeQuantAddress } from "@xyo-network/address";
33
+ function addressTo20Bytes(address) {
34
+ const decoded = tryDecodeQuantAddress(address);
35
+ return decoded === void 0 ? toUint8Array(address, 20).buffer : decoded.bytes.buffer;
36
+ }
32
37
 
33
38
  // src/Algorithm.ts
34
- var AccountAlgorithmPrefix = {
35
- "secp256k1": null,
36
- "ml-dsa-65": "qr1"
37
- };
38
- function algorithmFromAddress(address) {
39
- const underscore = address.indexOf("_");
40
- if (underscore === -1) return "secp256k1";
41
- const prefix = address.slice(0, underscore);
42
- if (prefix === AccountAlgorithmPrefix["ml-dsa-65"]) return "ml-dsa-65";
43
- throw new Error(`Unknown address algorithm prefix [${prefix}]`);
44
- }
45
- function stripAddressPrefix(address) {
46
- const underscore = address.indexOf("_");
47
- return underscore === -1 ? address : address.slice(underscore + 1);
48
- }
49
- function prefixForAlgorithm(algorithm) {
50
- const prefix = AccountAlgorithmPrefix[algorithm];
51
- return prefix === null ? "" : `${prefix}_`;
39
+ import { tryDecodeQuantAddress as tryDecodeQuantAddress2 } from "@xyo-network/address";
40
+ var AlgorithmHrpEntries = [
41
+ ["ml-dsa-65", "qm65"]
42
+ ];
43
+ var AccountAlgorithmHrp = Object.fromEntries(AlgorithmHrpEntries);
44
+ var HrpToAlgorithm = Object.fromEntries(
45
+ AlgorithmHrpEntries.map(([algorithm, hrp]) => [hrp, algorithm])
46
+ );
47
+ function hrpForAlgorithm(algorithm) {
48
+ return AccountAlgorithmHrp[algorithm];
52
49
  }
53
-
54
- // src/addressTo20Bytes.ts
55
- function addressTo20Bytes(address) {
56
- return toUint8Array(stripAddressPrefix(address), 20).buffer;
50
+ function algorithmFromAddress(address) {
51
+ const decoded = tryDecodeQuantAddress2(address);
52
+ if (decoded === void 0) return "secp256k1";
53
+ const algorithm = HrpToAlgorithm[decoded.hrp];
54
+ if (algorithm === void 0) {
55
+ throw new Error(`Unknown address algorithm HRP [${decoded.hrp}]`);
56
+ }
57
+ return algorithm;
57
58
  }
58
59
 
59
60
  // src/Jwt/constants.ts
@@ -79,7 +80,7 @@ async function verifySignature(address, hash, signature) {
79
80
  return await fn(address, hash, signature);
80
81
  }
81
82
  export {
82
- AccountAlgorithmPrefix,
83
+ AccountAlgorithmHrp,
83
84
  JwtAlg,
84
85
  JwtSchema,
85
86
  JwtTyp,
@@ -87,14 +88,13 @@ export {
87
88
  algorithmFromAddress,
88
89
  ethMessagePrefix,
89
90
  getVerifier,
91
+ hrpForAlgorithm,
90
92
  isAccountInstance,
91
93
  isInitializationConfig,
92
94
  isMnemonicInitializationConfig,
93
95
  isPhraseInitializationConfig,
94
96
  isPrivateKeyInitializationConfig,
95
- prefixForAlgorithm,
96
97
  registerVerifier,
97
- stripAddressPrefix,
98
98
  verifySignature
99
99
  };
100
100
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Account.ts", "../../src/addressTo20Bytes.ts", "../../src/Algorithm.ts", "../../src/Jwt/constants.ts", "../../src/VerifierRegistry.ts"],
4
- "sourcesContent": ["import type { Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\nimport type { XyoAddress } from '@xyo-network/address'\nimport type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model'\nimport type { PreviousHashStore } from '@xyo-network/previous-hash-store-model'\n\nimport type { AccountAlgorithm } from './Algorithm.ts'\nimport type { SignJwtOptions, SignJwtResult } from './Jwt/types.ts'\n\nexport const ethMessagePrefix = '\\u0019Ethereum Signed Message:\\n'\n\nexport interface PhraseInitializationConfig {\n phrase: string\n}\nexport interface PrivateKeyInitializationConfig {\n privateKey: ArrayBufferLike\n}\nexport interface MnemonicInitializationConfig {\n mnemonic: string\n path?: string\n}\nexport interface AccountOptions {\n previousHash?: ArrayBufferLike\n}\n\nexport type InitializationConfig = PhraseInitializationConfig | PrivateKeyInitializationConfig | MnemonicInitializationConfig\n\nexport type AccountConfig = InitializationConfig & AccountOptions\n\nexport const isPhraseInitializationConfig = (value: unknown): value is PhraseInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return typeof (value as PhraseInitializationConfig).phrase === 'string'\n }\n return false\n}\n\nexport const isPrivateKeyInitializationConfig = (value: unknown): value is PrivateKeyInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return isArrayBuffer((value as PrivateKeyInitializationConfig).privateKey)\n }\n return false\n}\n\nexport const isMnemonicInitializationConfig = (value: unknown): value is MnemonicInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return (\n typeof (value as MnemonicInitializationConfig).mnemonic === 'string' && typeof ((value as MnemonicInitializationConfig).path ?? '') === 'string'\n )\n }\n return false\n}\n\nexport const isInitializationConfig = (value: unknown): value is InitializationConfig => {\n return isPhraseInitializationConfig(value) || isPrivateKeyInitializationConfig(value) || isMnemonicInitializationConfig(value)\n}\n\nexport interface AccountInstance {\n readonly address: XyoAddress\n readonly addressBytes: ArrayBufferLike\n readonly algorithm: AccountAlgorithm\n previousHash: Hash | undefined\n previousHashBytes: ArrayBufferLike | undefined\n readonly private?: PrivateKeyInstance\n readonly public?: PublicKeyInstance\n sign: (hash: ArrayBufferLike, previousHash?: ArrayBufferLike) => Promise<[ArrayBufferLike, Hash?]>\n signJwt: (options: SignJwtOptions) => Promise<SignJwtResult>\n verify: (msg: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n}\n\nexport const isAccountInstance = (account: unknown): account is AccountInstance => {\n if (typeof account !== 'object' || account === null) return false\n return typeof (account as { address?: unknown }).address === 'string'\n}\n\nexport interface AccountStatic<T extends AccountInstance = AccountInstance, C extends AccountConfig = AccountConfig> {\n previousHashStore?: PreviousHashStore\n create(options?: C): Promise<T>\n fromPrivateKey(key: ArrayBufferLike | bigint | string): Promise<AccountInstance>\n random(): Promise<AccountInstance>\n}\n", "import { toUint8Array } from '@xylabs/sdk-js'\n\nimport { stripAddressPrefix } from './Algorithm.ts'\n\nexport function addressTo20Bytes(address: string): ArrayBufferLike {\n return toUint8Array(stripAddressPrefix(address), 20).buffer\n}\n", "export type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65'\n\nexport const AccountAlgorithmPrefix = {\n 'secp256k1': null,\n 'ml-dsa-65': 'qr1',\n} as const satisfies Record<AccountAlgorithm, string | null>\n\nexport function algorithmFromAddress(address: string): AccountAlgorithm {\n const underscore = address.indexOf('_')\n // secp256k1 addresses are unprefixed bare 40-hex strings\n if (underscore === -1) return 'secp256k1'\n const prefix = address.slice(0, underscore)\n if (prefix === AccountAlgorithmPrefix['ml-dsa-65']) return 'ml-dsa-65'\n throw new Error(`Unknown address algorithm prefix [${prefix}]`)\n}\n\nexport function stripAddressPrefix(address: string): string {\n const underscore = address.indexOf('_')\n return underscore === -1 ? address : address.slice(underscore + 1)\n}\n\nexport function prefixForAlgorithm(algorithm: AccountAlgorithm): string {\n const prefix = AccountAlgorithmPrefix[algorithm]\n return prefix === null ? '' : `${prefix}_`\n}\n", "import { Enum } from '@xylabs/sdk-js'\n\nexport const JwtAlg = Enum({ ES256K: 'ES256K' } as const)\nexport type JwtAlg = Enum<typeof JwtAlg>\n\nexport const JwtTyp = Enum({ JWT: 'JWT' } as const)\nexport type JwtTyp = Enum<typeof JwtTyp>\n\nexport const JwtSchema = Enum({ Signin: 'network.xyo.auth.signin' } as const)\nexport type JwtSchema = Enum<typeof JwtSchema>\n", "import type { AccountAlgorithm } from './Algorithm.ts'\nimport { algorithmFromAddress } from './Algorithm.ts'\n\nexport type VerifySignatureFn = (address: string, hash: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n\nconst registry: Partial<Record<AccountAlgorithm, VerifySignatureFn>> = {}\n\nexport function registerVerifier(algorithm: AccountAlgorithm, fn: VerifySignatureFn): void {\n registry[algorithm] = fn\n}\n\nexport function getVerifier(algorithm: AccountAlgorithm): VerifySignatureFn | undefined {\n return registry[algorithm]\n}\n\nexport async function verifySignature(address: string, hash: ArrayBufferLike, signature: ArrayBufferLike): Promise<boolean> {\n const algorithm = algorithmFromAddress(address)\n const fn = registry[algorithm]\n if (!fn) {\n throw new Error(`No verifier registered for algorithm [${algorithm}]. Did you import the account package?`)\n }\n return await fn(address, hash, signature)\n}\n"],
5
- "mappings": ";AACA,SAAS,qBAAqB;AAQvB,IAAM,mBAAmB;AAoBzB,IAAM,+BAA+B,CAAC,UAAwD;AACnG,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO,OAAQ,MAAqC,WAAW;AAAA,EACjE;AACA,SAAO;AACT;AAEO,IAAM,mCAAmC,CAAC,UAA4D;AAC3G,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO,cAAe,MAAyC,UAAU;AAAA,EAC3E;AACA,SAAO;AACT;AAEO,IAAM,iCAAiC,CAAC,UAA0D;AACvG,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WACE,OAAQ,MAAuC,aAAa,YAAY,QAAS,MAAuC,QAAQ,QAAQ;AAAA,EAE5I;AACA,SAAO;AACT;AAEO,IAAM,yBAAyB,CAAC,UAAkD;AACvF,SAAO,6BAA6B,KAAK,KAAK,iCAAiC,KAAK,KAAK,+BAA+B,KAAK;AAC/H;AAeO,IAAM,oBAAoB,CA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yCAAyC,SAAS,wCAAwC;AAAA,EAC5G;AACA,SAAO,MAAM,GAAG,SAAS,MAAM,SAAS;AAC1C;",
6
- "names": []
4
+ "sourcesContent": ["import type { Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\nimport type { XyoAddress } from '@xyo-network/address'\nimport type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model'\nimport type { PreviousHashStore } from '@xyo-network/previous-hash-store-model'\n\nimport type { AccountAlgorithm } from './Algorithm.ts'\nimport type { SignJwtOptions, SignJwtResult } from './Jwt/types.ts'\n\nexport const ethMessagePrefix = '\\u0019Ethereum Signed Message:\\n'\n\nexport interface PhraseInitializationConfig {\n phrase: string\n}\nexport interface PrivateKeyInitializationConfig {\n privateKey: ArrayBufferLike\n}\nexport interface MnemonicInitializationConfig {\n mnemonic: string\n path?: string\n}\nexport interface AccountOptions {\n previousHash?: ArrayBufferLike\n}\n\nexport type InitializationConfig = PhraseInitializationConfig | PrivateKeyInitializationConfig | MnemonicInitializationConfig\n\nexport type AccountConfig = InitializationConfig & AccountOptions\n\nexport const isPhraseInitializationConfig = (value: unknown): value is PhraseInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return typeof (value as PhraseInitializationConfig).phrase === 'string'\n }\n return false\n}\n\nexport const isPrivateKeyInitializationConfig = (value: unknown): value is PrivateKeyInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return isArrayBuffer((value as PrivateKeyInitializationConfig).privateKey)\n }\n return false\n}\n\nexport const isMnemonicInitializationConfig = (value: unknown): value is MnemonicInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return (\n typeof (value as MnemonicInitializationConfig).mnemonic === 'string' && typeof ((value as MnemonicInitializationConfig).path ?? '') === 'string'\n )\n }\n return false\n}\n\nexport const isInitializationConfig = (value: unknown): value is InitializationConfig => {\n return isPhraseInitializationConfig(value) || isPrivateKeyInitializationConfig(value) || isMnemonicInitializationConfig(value)\n}\n\nexport interface AccountInstance {\n readonly address: XyoAddress\n readonly addressBytes: ArrayBufferLike\n readonly algorithm: AccountAlgorithm\n previousHash: Hash | undefined\n previousHashBytes: ArrayBufferLike | undefined\n readonly private?: PrivateKeyInstance\n readonly public?: PublicKeyInstance\n sign: (hash: ArrayBufferLike, previousHash?: ArrayBufferLike) => Promise<[ArrayBufferLike, Hash?]>\n signJwt: (options: SignJwtOptions) => Promise<SignJwtResult>\n verify: (msg: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n}\n\nexport const isAccountInstance = (account: unknown): account is AccountInstance => {\n if (typeof account !== 'object' || account === null) return false\n return typeof (account as { address?: unknown }).address === 'string'\n}\n\nexport interface AccountStatic<T extends AccountInstance = AccountInstance, C extends AccountConfig = AccountConfig> {\n previousHashStore?: PreviousHashStore\n create(options?: C): Promise<T>\n fromPrivateKey(key: ArrayBufferLike | bigint | string): Promise<AccountInstance>\n random(): Promise<AccountInstance>\n}\n", "import { toUint8Array } from '@xylabs/sdk-js'\nimport { tryDecodeQuantAddress } from '@xyo-network/address'\n\nexport function addressTo20Bytes(address: string): ArrayBufferLike {\n const decoded = tryDecodeQuantAddress(address)\n // Quantum (bech32m) address \u2192 its decoded 20-byte payload; otherwise a legacy bare 40-hex address.\n return decoded === undefined ? toUint8Array(address, 20).buffer : decoded.bytes.buffer\n}\n", "import { tryDecodeQuantAddress } from '@xyo-network/address'\n\nexport type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65'\n\n// Single source of truth binding each quantum algorithm to its bech32m HRP (Human-Readable Part).\n// The HRP is what the address prefix communicates: 'qm65' = ML-DSA-65. secp256k1 has no HRP \u2014 its\n// addresses are legacy bare 40-hex strings. To add an algorithm: add a tuple here and register its\n// verifier (see VerifierRegistry).\nconst AlgorithmHrpEntries = [\n ['ml-dsa-65', 'qm65'],\n] as const satisfies readonly (readonly [AccountAlgorithm, string])[]\n\nexport const AccountAlgorithmHrp: Partial<Record<AccountAlgorithm, string>> = Object.fromEntries(AlgorithmHrpEntries)\n\nconst HrpToAlgorithm: Readonly<Record<string, AccountAlgorithm>> = Object.fromEntries(\n AlgorithmHrpEntries.map(([algorithm, hrp]) => [hrp, algorithm]),\n)\n\nexport function hrpForAlgorithm(algorithm: AccountAlgorithm): string | undefined {\n return AccountAlgorithmHrp[algorithm]\n}\n\nexport function algorithmFromAddress(address: string): AccountAlgorithm {\n const decoded = tryDecodeQuantAddress(address)\n // Not a bech32m quantum address \u2192 legacy secp256k1 bare-hex address.\n if (decoded === undefined) return 'secp256k1'\n const algorithm = HrpToAlgorithm[decoded.hrp]\n if (algorithm === undefined) {\n throw new Error(`Unknown address algorithm HRP [${decoded.hrp}]`)\n }\n return algorithm\n}\n", "import { Enum } from '@xylabs/sdk-js'\n\nexport const JwtAlg = Enum({ ES256K: 'ES256K' } as const)\nexport type JwtAlg = Enum<typeof JwtAlg>\n\nexport const JwtTyp = Enum({ JWT: 'JWT' } as const)\nexport type JwtTyp = Enum<typeof JwtTyp>\n\nexport const JwtSchema = Enum({ Signin: 'network.xyo.auth.signin' } as const)\nexport type JwtSchema = Enum<typeof JwtSchema>\n", "import type { AccountAlgorithm } from './Algorithm.ts'\nimport { algorithmFromAddress } from './Algorithm.ts'\n\nexport type VerifySignatureFn = (address: string, hash: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n\nconst registry: Partial<Record<AccountAlgorithm, VerifySignatureFn>> = {}\n\nexport function registerVerifier(algorithm: AccountAlgorithm, fn: VerifySignatureFn): void {\n registry[algorithm] = fn\n}\n\nexport function getVerifier(algorithm: AccountAlgorithm): VerifySignatureFn | undefined {\n return registry[algorithm]\n}\n\nexport async function verifySignature(address: string, hash: ArrayBufferLike, signature: ArrayBufferLike): Promise<boolean> {\n const algorithm = algorithmFromAddress(address)\n const fn = registry[algorithm]\n if (!fn) {\n throw new Error(`No verifier registered for algorithm [${algorithm}]. Did you import the account package?`)\n }\n return await fn(address, hash, signature)\n}\n"],
5
+ "mappings": ";AACA,SAAS,qBAAqB;AAQvB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BAAsB,OAAO;AAE7C,MAAI,YAAY,OAAW,QAAO;AAClC,QAAM,YAAY,eAAe,QAAQ,GAAG;AAC5C,MAAI,cAAc,QAAW;AAC3B,UAAM,IAAI,MAAM,kCAAkC,QAAQ,GAAG,GAAG;AAAA,EAClE;AACA,SAAO;AACT;;;AC/BA,SAAS,YAAY;AAEd,IAAM,SAAS,KAAK,EAAE,QAAQ,SAAS,CAAU;AAGjD,IAAM,SAAS,KAAK,EAAE,KAAK,MAAM,CAAU;AAG3C,IAAM,YAAY,KAAK,EAAE,QAAQ,0BAA0B,CAAU;;;ACH5E,IAAM,WAAiE,CAAC;AAEjE,SAAS,iBAAiB,WAA6B,IAA6B;AACzF,WAAS,SAAS,IAAI;AACxB;AAEO,SAAS,YAAY,WAA4D;AACtF,SAAO,SAAS,SAAS;AAC3B;AAEA,eAAsB,gBAAgB,SAAiB,MAAuB,WAA8C;AAC1H,QAAM,YAAY,qBAAqB,OAAO;AAC9C,QAAM,KAAK,SAAS,SAAS;AAC7B,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,yCAAyC,SAAS,wCAAwC;AAAA,EAC5G;AACA,SAAO,MAAM,GAAG,SAAS,MAAM,SAAS;AAC1C;",
6
+ "names": ["tryDecodeQuantAddress"]
7
7
  }
@@ -1,9 +1,5 @@
1
1
  export type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65';
2
- export declare const AccountAlgorithmPrefix: {
3
- readonly secp256k1: null;
4
- readonly 'ml-dsa-65': "qr1";
5
- };
2
+ export declare const AccountAlgorithmHrp: Partial<Record<AccountAlgorithm, string>>;
3
+ export declare function hrpForAlgorithm(algorithm: AccountAlgorithm): string | undefined;
6
4
  export declare function algorithmFromAddress(address: string): AccountAlgorithm;
7
- export declare function stripAddressPrefix(address: string): string;
8
- export declare function prefixForAlgorithm(algorithm: AccountAlgorithm): string;
9
5
  //# sourceMappingURL=Algorithm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Algorithm.d.ts","sourceRoot":"","sources":["../../src/Algorithm.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,CAAA;AAExD,eAAO,MAAM,sBAAsB;;;CAGyB,CAAA;AAE5D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAOtE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,CAGtE"}
1
+ {"version":3,"file":"Algorithm.d.ts","sourceRoot":"","sources":["../../src/Algorithm.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,CAAA;AAUxD,eAAO,MAAM,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAA2C,CAAA;AAMrH,wBAAgB,eAAe,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAE/E;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAStE"}
@@ -1 +1 @@
1
- {"version":3,"file":"addressTo20Bytes.d.ts","sourceRoot":"","sources":["../../src/addressTo20Bytes.ts"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAEjE"}
1
+ {"version":3,"file":"addressTo20Bytes.d.ts","sourceRoot":"","sources":["../../src/addressTo20Bytes.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAIjE"}
@@ -29,31 +29,32 @@ var isAccountInstance = (account) => {
29
29
 
30
30
  // src/addressTo20Bytes.ts
31
31
  import { toUint8Array } from "@xylabs/sdk-js";
32
+ import { tryDecodeQuantAddress } from "@xyo-network/address";
33
+ function addressTo20Bytes(address) {
34
+ const decoded = tryDecodeQuantAddress(address);
35
+ return decoded === void 0 ? toUint8Array(address, 20).buffer : decoded.bytes.buffer;
36
+ }
32
37
 
33
38
  // src/Algorithm.ts
34
- var AccountAlgorithmPrefix = {
35
- "secp256k1": null,
36
- "ml-dsa-65": "qr1"
37
- };
38
- function algorithmFromAddress(address) {
39
- const underscore = address.indexOf("_");
40
- if (underscore === -1) return "secp256k1";
41
- const prefix = address.slice(0, underscore);
42
- if (prefix === AccountAlgorithmPrefix["ml-dsa-65"]) return "ml-dsa-65";
43
- throw new Error(`Unknown address algorithm prefix [${prefix}]`);
44
- }
45
- function stripAddressPrefix(address) {
46
- const underscore = address.indexOf("_");
47
- return underscore === -1 ? address : address.slice(underscore + 1);
48
- }
49
- function prefixForAlgorithm(algorithm) {
50
- const prefix = AccountAlgorithmPrefix[algorithm];
51
- return prefix === null ? "" : `${prefix}_`;
39
+ import { tryDecodeQuantAddress as tryDecodeQuantAddress2 } from "@xyo-network/address";
40
+ var AlgorithmHrpEntries = [
41
+ ["ml-dsa-65", "qm65"]
42
+ ];
43
+ var AccountAlgorithmHrp = Object.fromEntries(AlgorithmHrpEntries);
44
+ var HrpToAlgorithm = Object.fromEntries(
45
+ AlgorithmHrpEntries.map(([algorithm, hrp]) => [hrp, algorithm])
46
+ );
47
+ function hrpForAlgorithm(algorithm) {
48
+ return AccountAlgorithmHrp[algorithm];
52
49
  }
53
-
54
- // src/addressTo20Bytes.ts
55
- function addressTo20Bytes(address) {
56
- return toUint8Array(stripAddressPrefix(address), 20).buffer;
50
+ function algorithmFromAddress(address) {
51
+ const decoded = tryDecodeQuantAddress2(address);
52
+ if (decoded === void 0) return "secp256k1";
53
+ const algorithm = HrpToAlgorithm[decoded.hrp];
54
+ if (algorithm === void 0) {
55
+ throw new Error(`Unknown address algorithm HRP [${decoded.hrp}]`);
56
+ }
57
+ return algorithm;
57
58
  }
58
59
 
59
60
  // src/Jwt/constants.ts
@@ -79,7 +80,7 @@ async function verifySignature(address, hash, signature) {
79
80
  return await fn(address, hash, signature);
80
81
  }
81
82
  export {
82
- AccountAlgorithmPrefix,
83
+ AccountAlgorithmHrp,
83
84
  JwtAlg,
84
85
  JwtSchema,
85
86
  JwtTyp,
@@ -87,14 +88,13 @@ export {
87
88
  algorithmFromAddress,
88
89
  ethMessagePrefix,
89
90
  getVerifier,
91
+ hrpForAlgorithm,
90
92
  isAccountInstance,
91
93
  isInitializationConfig,
92
94
  isMnemonicInitializationConfig,
93
95
  isPhraseInitializationConfig,
94
96
  isPrivateKeyInitializationConfig,
95
- prefixForAlgorithm,
96
97
  registerVerifier,
97
- stripAddressPrefix,
98
98
  verifySignature
99
99
  };
100
100
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Account.ts", "../../src/addressTo20Bytes.ts", "../../src/Algorithm.ts", "../../src/Jwt/constants.ts", "../../src/VerifierRegistry.ts"],
4
- "sourcesContent": ["import type { Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\nimport type { XyoAddress } from '@xyo-network/address'\nimport type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model'\nimport type { PreviousHashStore } from '@xyo-network/previous-hash-store-model'\n\nimport type { AccountAlgorithm } from './Algorithm.ts'\nimport type { SignJwtOptions, SignJwtResult } from './Jwt/types.ts'\n\nexport const ethMessagePrefix = '\\u0019Ethereum Signed Message:\\n'\n\nexport interface PhraseInitializationConfig {\n phrase: string\n}\nexport interface PrivateKeyInitializationConfig {\n privateKey: ArrayBufferLike\n}\nexport interface MnemonicInitializationConfig {\n mnemonic: string\n path?: string\n}\nexport interface AccountOptions {\n previousHash?: ArrayBufferLike\n}\n\nexport type InitializationConfig = PhraseInitializationConfig | PrivateKeyInitializationConfig | MnemonicInitializationConfig\n\nexport type AccountConfig = InitializationConfig & AccountOptions\n\nexport const isPhraseInitializationConfig = (value: unknown): value is PhraseInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return typeof (value as PhraseInitializationConfig).phrase === 'string'\n }\n return false\n}\n\nexport const isPrivateKeyInitializationConfig = (value: unknown): value is PrivateKeyInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return isArrayBuffer((value as PrivateKeyInitializationConfig).privateKey)\n }\n return false\n}\n\nexport const isMnemonicInitializationConfig = (value: unknown): value is MnemonicInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return (\n typeof (value as MnemonicInitializationConfig).mnemonic === 'string' && typeof ((value as MnemonicInitializationConfig).path ?? '') === 'string'\n )\n }\n return false\n}\n\nexport const isInitializationConfig = (value: unknown): value is InitializationConfig => {\n return isPhraseInitializationConfig(value) || isPrivateKeyInitializationConfig(value) || isMnemonicInitializationConfig(value)\n}\n\nexport interface AccountInstance {\n readonly address: XyoAddress\n readonly addressBytes: ArrayBufferLike\n readonly algorithm: AccountAlgorithm\n previousHash: Hash | undefined\n previousHashBytes: ArrayBufferLike | undefined\n readonly private?: PrivateKeyInstance\n readonly public?: PublicKeyInstance\n sign: (hash: ArrayBufferLike, previousHash?: ArrayBufferLike) => Promise<[ArrayBufferLike, Hash?]>\n signJwt: (options: SignJwtOptions) => Promise<SignJwtResult>\n verify: (msg: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n}\n\nexport const isAccountInstance = (account: unknown): account is AccountInstance => {\n if (typeof account !== 'object' || account === null) return false\n return typeof (account as { address?: unknown }).address === 'string'\n}\n\nexport interface AccountStatic<T extends AccountInstance = AccountInstance, C extends AccountConfig = AccountConfig> {\n previousHashStore?: PreviousHashStore\n create(options?: C): Promise<T>\n fromPrivateKey(key: ArrayBufferLike | bigint | string): Promise<AccountInstance>\n random(): Promise<AccountInstance>\n}\n", "import { toUint8Array } from '@xylabs/sdk-js'\n\nimport { stripAddressPrefix } from './Algorithm.ts'\n\nexport function addressTo20Bytes(address: string): ArrayBufferLike {\n return toUint8Array(stripAddressPrefix(address), 20).buffer\n}\n", "export type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65'\n\nexport const AccountAlgorithmPrefix = {\n 'secp256k1': null,\n 'ml-dsa-65': 'qr1',\n} as const satisfies Record<AccountAlgorithm, string | null>\n\nexport function algorithmFromAddress(address: string): AccountAlgorithm {\n const underscore = address.indexOf('_')\n // secp256k1 addresses are unprefixed bare 40-hex strings\n if (underscore === -1) return 'secp256k1'\n const prefix = address.slice(0, underscore)\n if (prefix === AccountAlgorithmPrefix['ml-dsa-65']) return 'ml-dsa-65'\n throw new Error(`Unknown address algorithm prefix [${prefix}]`)\n}\n\nexport function stripAddressPrefix(address: string): string {\n const underscore = address.indexOf('_')\n return underscore === -1 ? address : address.slice(underscore + 1)\n}\n\nexport function prefixForAlgorithm(algorithm: AccountAlgorithm): string {\n const prefix = AccountAlgorithmPrefix[algorithm]\n return prefix === null ? '' : `${prefix}_`\n}\n", "import { Enum } from '@xylabs/sdk-js'\n\nexport const JwtAlg = Enum({ ES256K: 'ES256K' } as const)\nexport type JwtAlg = Enum<typeof JwtAlg>\n\nexport const JwtTyp = Enum({ JWT: 'JWT' } as const)\nexport type JwtTyp = Enum<typeof JwtTyp>\n\nexport const JwtSchema = Enum({ Signin: 'network.xyo.auth.signin' } as const)\nexport type JwtSchema = Enum<typeof JwtSchema>\n", "import type { AccountAlgorithm } from './Algorithm.ts'\nimport { algorithmFromAddress } from './Algorithm.ts'\n\nexport type VerifySignatureFn = (address: string, hash: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n\nconst registry: Partial<Record<AccountAlgorithm, VerifySignatureFn>> = {}\n\nexport function registerVerifier(algorithm: AccountAlgorithm, fn: VerifySignatureFn): void {\n registry[algorithm] = fn\n}\n\nexport function getVerifier(algorithm: AccountAlgorithm): VerifySignatureFn | undefined {\n return registry[algorithm]\n}\n\nexport async function verifySignature(address: string, hash: ArrayBufferLike, signature: ArrayBufferLike): Promise<boolean> {\n const algorithm = algorithmFromAddress(address)\n const fn = registry[algorithm]\n if (!fn) {\n throw new Error(`No verifier registered for algorithm [${algorithm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nE;AAEO,SAAS,mBAAmB,WAAqC;AACtE,QAAM,SAAS,uBAAuB,SAAS;AAC/C,SAAO,WAAW,OAAO,KAAK,GAAG,MAAM;AACzC;;;ADpBO,SAAS,iBAAiB,SAAkC;AACjE,SAAO,aAAa,mBAAmB,OAAO,GAAG,EAAE,EAAE;AACvD;;;AENA,SAAS,YAAY;AAEd,IAAM,SAAS,KAAK,EAAE,QAAQ,SAAS,CAAU;AAGjD,IAAM,SAAS,KAAK,EAAE,KAAK,MAAM,CAAU;AAG3C,IAAM,YAAY,KAAK,EAAE,QAAQ,0BAA0B,CAAU;;;ACH5E,IAAM,WAAiE,CAAC;AAEjE,SAAS,iBAAiB,WAA6B,IAA6B;AACzF,WAAS,SAAS,IAAI;AACxB;AAEO,SAAS,YAAY,WAA4D;AACtF,SAAO,SAAS,SAAS;AAC3B;AAEA,eAAsB,gBAAgB,SAAiB,MAAuB,WAA8C;AAC1H,QAAM,YAAY,qBAAqB,OAAO;AAC9C,QAAM,KAAK,SAAS,SAAS;AAC7B,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,yCAAyC,SAAS,wCAAwC;AAAA,EAC5G;AACA,SAAO,MAAM,GAAG,SAAS,MAAM,SAAS;AAC1C;",
6
- "names": []
4
+ "sourcesContent": ["import type { Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\nimport type { XyoAddress } from '@xyo-network/address'\nimport type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model'\nimport type { PreviousHashStore } from '@xyo-network/previous-hash-store-model'\n\nimport type { AccountAlgorithm } from './Algorithm.ts'\nimport type { SignJwtOptions, SignJwtResult } from './Jwt/types.ts'\n\nexport const ethMessagePrefix = '\\u0019Ethereum Signed Message:\\n'\n\nexport interface PhraseInitializationConfig {\n phrase: string\n}\nexport interface PrivateKeyInitializationConfig {\n privateKey: ArrayBufferLike\n}\nexport interface MnemonicInitializationConfig {\n mnemonic: string\n path?: string\n}\nexport interface AccountOptions {\n previousHash?: ArrayBufferLike\n}\n\nexport type InitializationConfig = PhraseInitializationConfig | PrivateKeyInitializationConfig | MnemonicInitializationConfig\n\nexport type AccountConfig = InitializationConfig & AccountOptions\n\nexport const isPhraseInitializationConfig = (value: unknown): value is PhraseInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return typeof (value as PhraseInitializationConfig).phrase === 'string'\n }\n return false\n}\n\nexport const isPrivateKeyInitializationConfig = (value: unknown): value is PrivateKeyInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return isArrayBuffer((value as PrivateKeyInitializationConfig).privateKey)\n }\n return false\n}\n\nexport const isMnemonicInitializationConfig = (value: unknown): value is MnemonicInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return (\n typeof (value as MnemonicInitializationConfig).mnemonic === 'string' && typeof ((value as MnemonicInitializationConfig).path ?? '') === 'string'\n )\n }\n return false\n}\n\nexport const isInitializationConfig = (value: unknown): value is InitializationConfig => {\n return isPhraseInitializationConfig(value) || isPrivateKeyInitializationConfig(value) || isMnemonicInitializationConfig(value)\n}\n\nexport interface AccountInstance {\n readonly address: XyoAddress\n readonly addressBytes: ArrayBufferLike\n readonly algorithm: AccountAlgorithm\n previousHash: Hash | undefined\n previousHashBytes: ArrayBufferLike | undefined\n readonly private?: PrivateKeyInstance\n readonly public?: PublicKeyInstance\n sign: (hash: ArrayBufferLike, previousHash?: ArrayBufferLike) => Promise<[ArrayBufferLike, Hash?]>\n signJwt: (options: SignJwtOptions) => Promise<SignJwtResult>\n verify: (msg: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n}\n\nexport const isAccountInstance = (account: unknown): account is AccountInstance => {\n if (typeof account !== 'object' || account === null) return false\n return typeof (account as { address?: unknown }).address === 'string'\n}\n\nexport interface AccountStatic<T extends AccountInstance = AccountInstance, C extends AccountConfig = AccountConfig> {\n previousHashStore?: PreviousHashStore\n create(options?: C): Promise<T>\n fromPrivateKey(key: ArrayBufferLike | bigint | string): Promise<AccountInstance>\n random(): Promise<AccountInstance>\n}\n", "import { toUint8Array } from '@xylabs/sdk-js'\nimport { tryDecodeQuantAddress } from '@xyo-network/address'\n\nexport function addressTo20Bytes(address: string): ArrayBufferLike {\n const decoded = tryDecodeQuantAddress(address)\n // Quantum (bech32m) address \u2192 its decoded 20-byte payload; otherwise a legacy bare 40-hex address.\n return decoded === undefined ? toUint8Array(address, 20).buffer : decoded.bytes.buffer\n}\n", "import { tryDecodeQuantAddress } from '@xyo-network/address'\n\nexport type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65'\n\n// Single source of truth binding each quantum algorithm to its bech32m HRP (Human-Readable Part).\n// The HRP is what the address prefix communicates: 'qm65' = ML-DSA-65. secp256k1 has no HRP \u2014 its\n// addresses are legacy bare 40-hex strings. To add an algorithm: add a tuple here and register its\n// verifier (see VerifierRegistry).\nconst AlgorithmHrpEntries = [\n ['ml-dsa-65', 'qm65'],\n] as const satisfies readonly (readonly [AccountAlgorithm, string])[]\n\nexport const AccountAlgorithmHrp: Partial<Record<AccountAlgorithm, string>> = Object.fromEntries(AlgorithmHrpEntries)\n\nconst HrpToAlgorithm: Readonly<Record<string, AccountAlgorithm>> = Object.fromEntries(\n AlgorithmHrpEntries.map(([algorithm, hrp]) => [hrp, algorithm]),\n)\n\nexport function hrpForAlgorithm(algorithm: AccountAlgorithm): string | undefined {\n return AccountAlgorithmHrp[algorithm]\n}\n\nexport function algorithmFromAddress(address: string): AccountAlgorithm {\n const decoded = tryDecodeQuantAddress(address)\n // Not a bech32m quantum address \u2192 legacy secp256k1 bare-hex address.\n if (decoded === undefined) return 'secp256k1'\n const algorithm = HrpToAlgorithm[decoded.hrp]\n if (algorithm === undefined) {\n throw new Error(`Unknown address algorithm HRP [${decoded.hrp}]`)\n }\n return algorithm\n}\n", "import { Enum } from '@xylabs/sdk-js'\n\nexport const JwtAlg = Enum({ ES256K: 'ES256K' } as const)\nexport type JwtAlg = Enum<typeof JwtAlg>\n\nexport const JwtTyp = Enum({ JWT: 'JWT' } as const)\nexport type JwtTyp = Enum<typeof JwtTyp>\n\nexport const JwtSchema = Enum({ Signin: 'network.xyo.auth.signin' } as const)\nexport type JwtSchema = Enum<typeof JwtSchema>\n", "import type { AccountAlgorithm } from './Algorithm.ts'\nimport { algorithmFromAddress } from './Algorithm.ts'\n\nexport type VerifySignatureFn = (address: string, hash: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n\nconst registry: Partial<Record<AccountAlgorithm, VerifySignatureFn>> = {}\n\nexport function registerVerifier(algorithm: AccountAlgorithm, fn: VerifySignatureFn): void {\n registry[algorithm] = fn\n}\n\nexport function getVerifier(algorithm: AccountAlgorithm): VerifySignatureFn | undefined {\n return registry[algorithm]\n}\n\nexport async function verifySignature(address: string, hash: ArrayBufferLike, signature: ArrayBufferLike): Promise<boolean> {\n const algorithm = algorithmFromAddress(address)\n const fn = registry[algorithm]\n if (!fn) {\n throw new Error(`No verifier registered for algorithm [${algorithm}]. Did you import the account package?`)\n }\n return await fn(address, hash, signature)\n}\n"],
5
+ "mappings": ";AACA,SAAS,qBAAqB;AAQvB,IAAM,mBAAmB;AAoBzB,IAAM,+BAA+B,CAAC,UAAwD;AACnG,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO,OAAQ,MAAqC,WAAW;AAAA,EACjE;AACA,SAAO;AACT;AAEO,IAAM,mCAAmC,CAAC,UAA4D;AAC3G,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO,cAAe,MAAyC,UAAU;AAAA,EAC3E;AACA,SAAO;AACT;AAEO,IAAM,iCAAiC,CAAC,UAA0D;AACvG,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WACE,OAAQ,MAAuC,aAAa,YAAY,QAAS,MAAuC,QAAQ,QAAQ;AAAA,EAE5I;AACA,SAAO;AACT;AAEO,IAAM,yBAAyB,CAAC,UAAkD;AACvF,SAAO,6BAA6B,KAAK,KAAK,iCAAiC,KAAK,KAAK,+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8C;AAC1H,QAAM,YAAY,qBAAqB,OAAO;AAC9C,QAAM,KAAK,SAAS,SAAS;AAC7B,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,yCAAyC,SAAS,wCAAwC;AAAA,EAC5G;AACA,SAAO,MAAM,GAAG,SAAS,MAAM,SAAS;AAC1C;",
6
+ "names": ["tryDecodeQuantAddress"]
7
7
  }
@@ -1,9 +1,5 @@
1
1
  export type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65';
2
- export declare const AccountAlgorithmPrefix: {
3
- readonly secp256k1: null;
4
- readonly 'ml-dsa-65': "qr1";
5
- };
2
+ export declare const AccountAlgorithmHrp: Partial<Record<AccountAlgorithm, string>>;
3
+ export declare function hrpForAlgorithm(algorithm: AccountAlgorithm): string | undefined;
6
4
  export declare function algorithmFromAddress(address: string): AccountAlgorithm;
7
- export declare function stripAddressPrefix(address: string): string;
8
- export declare function prefixForAlgorithm(algorithm: AccountAlgorithm): string;
9
5
  //# sourceMappingURL=Algorithm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Algorithm.d.ts","sourceRoot":"","sources":["../../src/Algorithm.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,CAAA;AAExD,eAAO,MAAM,sBAAsB;;;CAGyB,CAAA;AAE5D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAOtE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,CAGtE"}
1
+ {"version":3,"file":"Algorithm.d.ts","sourceRoot":"","sources":["../../src/Algorithm.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,CAAA;AAUxD,eAAO,MAAM,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAA2C,CAAA;AAMrH,wBAAgB,eAAe,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAE/E;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAStE"}
@@ -1 +1 @@
1
- {"version":3,"file":"addressTo20Bytes.d.ts","sourceRoot":"","sources":["../../src/addressTo20Bytes.ts"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAEjE"}
1
+ {"version":3,"file":"addressTo20Bytes.d.ts","sourceRoot":"","sources":["../../src/addressTo20Bytes.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAIjE"}
@@ -29,31 +29,32 @@ var isAccountInstance = (account) => {
29
29
 
30
30
  // src/addressTo20Bytes.ts
31
31
  import { toUint8Array } from "@xylabs/sdk-js";
32
+ import { tryDecodeQuantAddress } from "@xyo-network/address";
33
+ function addressTo20Bytes(address) {
34
+ const decoded = tryDecodeQuantAddress(address);
35
+ return decoded === void 0 ? toUint8Array(address, 20).buffer : decoded.bytes.buffer;
36
+ }
32
37
 
33
38
  // src/Algorithm.ts
34
- var AccountAlgorithmPrefix = {
35
- "secp256k1": null,
36
- "ml-dsa-65": "qr1"
37
- };
38
- function algorithmFromAddress(address) {
39
- const underscore = address.indexOf("_");
40
- if (underscore === -1) return "secp256k1";
41
- const prefix = address.slice(0, underscore);
42
- if (prefix === AccountAlgorithmPrefix["ml-dsa-65"]) return "ml-dsa-65";
43
- throw new Error(`Unknown address algorithm prefix [${prefix}]`);
44
- }
45
- function stripAddressPrefix(address) {
46
- const underscore = address.indexOf("_");
47
- return underscore === -1 ? address : address.slice(underscore + 1);
48
- }
49
- function prefixForAlgorithm(algorithm) {
50
- const prefix = AccountAlgorithmPrefix[algorithm];
51
- return prefix === null ? "" : `${prefix}_`;
39
+ import { tryDecodeQuantAddress as tryDecodeQuantAddress2 } from "@xyo-network/address";
40
+ var AlgorithmHrpEntries = [
41
+ ["ml-dsa-65", "qm65"]
42
+ ];
43
+ var AccountAlgorithmHrp = Object.fromEntries(AlgorithmHrpEntries);
44
+ var HrpToAlgorithm = Object.fromEntries(
45
+ AlgorithmHrpEntries.map(([algorithm, hrp]) => [hrp, algorithm])
46
+ );
47
+ function hrpForAlgorithm(algorithm) {
48
+ return AccountAlgorithmHrp[algorithm];
52
49
  }
53
-
54
- // src/addressTo20Bytes.ts
55
- function addressTo20Bytes(address) {
56
- return toUint8Array(stripAddressPrefix(address), 20).buffer;
50
+ function algorithmFromAddress(address) {
51
+ const decoded = tryDecodeQuantAddress2(address);
52
+ if (decoded === void 0) return "secp256k1";
53
+ const algorithm = HrpToAlgorithm[decoded.hrp];
54
+ if (algorithm === void 0) {
55
+ throw new Error(`Unknown address algorithm HRP [${decoded.hrp}]`);
56
+ }
57
+ return algorithm;
57
58
  }
58
59
 
59
60
  // src/Jwt/constants.ts
@@ -79,7 +80,7 @@ async function verifySignature(address, hash, signature) {
79
80
  return await fn(address, hash, signature);
80
81
  }
81
82
  export {
82
- AccountAlgorithmPrefix,
83
+ AccountAlgorithmHrp,
83
84
  JwtAlg,
84
85
  JwtSchema,
85
86
  JwtTyp,
@@ -87,14 +88,13 @@ export {
87
88
  algorithmFromAddress,
88
89
  ethMessagePrefix,
89
90
  getVerifier,
91
+ hrpForAlgorithm,
90
92
  isAccountInstance,
91
93
  isInitializationConfig,
92
94
  isMnemonicInitializationConfig,
93
95
  isPhraseInitializationConfig,
94
96
  isPrivateKeyInitializationConfig,
95
- prefixForAlgorithm,
96
97
  registerVerifier,
97
- stripAddressPrefix,
98
98
  verifySignature
99
99
  };
100
100
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Account.ts", "../../src/addressTo20Bytes.ts", "../../src/Algorithm.ts", "../../src/Jwt/constants.ts", "../../src/VerifierRegistry.ts"],
4
- "sourcesContent": ["import type { Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\nimport type { XyoAddress } from '@xyo-network/address'\nimport type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model'\nimport type { PreviousHashStore } from '@xyo-network/previous-hash-store-model'\n\nimport type { AccountAlgorithm } from './Algorithm.ts'\nimport type { SignJwtOptions, SignJwtResult } from './Jwt/types.ts'\n\nexport const ethMessagePrefix = '\\u0019Ethereum Signed Message:\\n'\n\nexport interface PhraseInitializationConfig {\n phrase: string\n}\nexport interface PrivateKeyInitializationConfig {\n privateKey: ArrayBufferLike\n}\nexport interface MnemonicInitializationConfig {\n mnemonic: string\n path?: string\n}\nexport interface AccountOptions {\n previousHash?: ArrayBufferLike\n}\n\nexport type InitializationConfig = PhraseInitializationConfig | PrivateKeyInitializationConfig | MnemonicInitializationConfig\n\nexport type AccountConfig = InitializationConfig & AccountOptions\n\nexport const isPhraseInitializationConfig = (value: unknown): value is PhraseInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return typeof (value as PhraseInitializationConfig).phrase === 'string'\n }\n return false\n}\n\nexport const isPrivateKeyInitializationConfig = (value: unknown): value is PrivateKeyInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return isArrayBuffer((value as PrivateKeyInitializationConfig).privateKey)\n }\n return false\n}\n\nexport const isMnemonicInitializationConfig = (value: unknown): value is MnemonicInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return (\n typeof (value as MnemonicInitializationConfig).mnemonic === 'string' && typeof ((value as MnemonicInitializationConfig).path ?? '') === 'string'\n )\n }\n return false\n}\n\nexport const isInitializationConfig = (value: unknown): value is InitializationConfig => {\n return isPhraseInitializationConfig(value) || isPrivateKeyInitializationConfig(value) || isMnemonicInitializationConfig(value)\n}\n\nexport interface AccountInstance {\n readonly address: XyoAddress\n readonly addressBytes: ArrayBufferLike\n readonly algorithm: AccountAlgorithm\n previousHash: Hash | undefined\n previousHashBytes: ArrayBufferLike | undefined\n readonly private?: PrivateKeyInstance\n readonly public?: PublicKeyInstance\n sign: (hash: ArrayBufferLike, previousHash?: ArrayBufferLike) => Promise<[ArrayBufferLike, Hash?]>\n signJwt: (options: SignJwtOptions) => Promise<SignJwtResult>\n verify: (msg: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n}\n\nexport const isAccountInstance = (account: unknown): account is AccountInstance => {\n if (typeof account !== 'object' || account === null) return false\n return typeof (account as { address?: unknown }).address === 'string'\n}\n\nexport interface AccountStatic<T extends AccountInstance = AccountInstance, C extends AccountConfig = AccountConfig> {\n previousHashStore?: PreviousHashStore\n create(options?: C): Promise<T>\n fromPrivateKey(key: ArrayBufferLike | bigint | string): Promise<AccountInstance>\n random(): Promise<AccountInstance>\n}\n", "import { toUint8Array } from '@xylabs/sdk-js'\n\nimport { stripAddressPrefix } from './Algorithm.ts'\n\nexport function addressTo20Bytes(address: string): ArrayBufferLike {\n return toUint8Array(stripAddressPrefix(address), 20).buffer\n}\n", "export type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65'\n\nexport const AccountAlgorithmPrefix = {\n 'secp256k1': null,\n 'ml-dsa-65': 'qr1',\n} as const satisfies Record<AccountAlgorithm, string | null>\n\nexport function algorithmFromAddress(address: string): AccountAlgorithm {\n const underscore = address.indexOf('_')\n // secp256k1 addresses are unprefixed bare 40-hex strings\n if (underscore === -1) return 'secp256k1'\n const prefix = address.slice(0, underscore)\n if (prefix === AccountAlgorithmPrefix['ml-dsa-65']) return 'ml-dsa-65'\n throw new Error(`Unknown address algorithm prefix [${prefix}]`)\n}\n\nexport function stripAddressPrefix(address: string): string {\n const underscore = address.indexOf('_')\n return underscore === -1 ? address : address.slice(underscore + 1)\n}\n\nexport function prefixForAlgorithm(algorithm: AccountAlgorithm): string {\n const prefix = AccountAlgorithmPrefix[algorithm]\n return prefix === null ? '' : `${prefix}_`\n}\n", "import { Enum } from '@xylabs/sdk-js'\n\nexport const JwtAlg = Enum({ ES256K: 'ES256K' } as const)\nexport type JwtAlg = Enum<typeof JwtAlg>\n\nexport const JwtTyp = Enum({ JWT: 'JWT' } as const)\nexport type JwtTyp = Enum<typeof JwtTyp>\n\nexport const JwtSchema = Enum({ Signin: 'network.xyo.auth.signin' } as const)\nexport type JwtSchema = Enum<typeof JwtSchema>\n", "import type { AccountAlgorithm } from './Algorithm.ts'\nimport { algorithmFromAddress } from './Algorithm.ts'\n\nexport type VerifySignatureFn = (address: string, hash: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n\nconst registry: Partial<Record<AccountAlgorithm, VerifySignatureFn>> = {}\n\nexport function registerVerifier(algorithm: AccountAlgorithm, fn: VerifySignatureFn): void {\n registry[algorithm] = fn\n}\n\nexport function getVerifier(algorithm: AccountAlgorithm): VerifySignatureFn | undefined {\n return registry[algorithm]\n}\n\nexport async function verifySignature(address: string, hash: ArrayBufferLike, signature: ArrayBufferLike): Promise<boolean> {\n const algorithm = algorithmFromAddress(address)\n const fn = registry[algorithm]\n if (!fn) {\n throw new Error(`No verifier registered for algorithm [${algorithm}]. Did you import the account package?`)\n }\n return await fn(address, hash, signature)\n}\n"],
5
- "mappings": ";AACA,SAAS,qBAAqB;AAQvB,IAAM,mBAAmB;AAoBzB,IAAM,+BAA+B,CAAC,UAAwD;AACnG,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO,OAAQ,MAAqC,WAAW;AAAA,EACjE;AACA,SAAO;AACT;AAEO,IAAM,mCAAmC,CAAC,UAA4D;AAC3G,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO,cAAe,MAAyC,UAAU;AAAA,EAC3E;AACA,SAAO;AACT;AAEO,IAAM,iCAAiC,CAAC,UAA0D;AACvG,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WACE,OAAQ,MAAuC,aAAa,YAAY,QAAS,MAAuC,QAAQ,QAAQ;AAAA,EAE5I;AACA,SAAO;AACT;AAE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MAAuB,WAA8C;AAC1H,QAAM,YAAY,qBAAqB,OAAO;AAC9C,QAAM,KAAK,SAAS,SAAS;AAC7B,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,yCAAyC,SAAS,wCAAwC;AAAA,EAC5G;AACA,SAAO,MAAM,GAAG,SAAS,MAAM,SAAS;AAC1C;",
6
- "names": []
4
+ "sourcesContent": ["import type { Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\nimport type { XyoAddress } from '@xyo-network/address'\nimport type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model'\nimport type { PreviousHashStore } from '@xyo-network/previous-hash-store-model'\n\nimport type { AccountAlgorithm } from './Algorithm.ts'\nimport type { SignJwtOptions, SignJwtResult } from './Jwt/types.ts'\n\nexport const ethMessagePrefix = '\\u0019Ethereum Signed Message:\\n'\n\nexport interface PhraseInitializationConfig {\n phrase: string\n}\nexport interface PrivateKeyInitializationConfig {\n privateKey: ArrayBufferLike\n}\nexport interface MnemonicInitializationConfig {\n mnemonic: string\n path?: string\n}\nexport interface AccountOptions {\n previousHash?: ArrayBufferLike\n}\n\nexport type InitializationConfig = PhraseInitializationConfig | PrivateKeyInitializationConfig | MnemonicInitializationConfig\n\nexport type AccountConfig = InitializationConfig & AccountOptions\n\nexport const isPhraseInitializationConfig = (value: unknown): value is PhraseInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return typeof (value as PhraseInitializationConfig).phrase === 'string'\n }\n return false\n}\n\nexport const isPrivateKeyInitializationConfig = (value: unknown): value is PrivateKeyInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return isArrayBuffer((value as PrivateKeyInitializationConfig).privateKey)\n }\n return false\n}\n\nexport const isMnemonicInitializationConfig = (value: unknown): value is MnemonicInitializationConfig => {\n if (typeof value === 'object' && value !== null) {\n return (\n typeof (value as MnemonicInitializationConfig).mnemonic === 'string' && typeof ((value as MnemonicInitializationConfig).path ?? '') === 'string'\n )\n }\n return false\n}\n\nexport const isInitializationConfig = (value: unknown): value is InitializationConfig => {\n return isPhraseInitializationConfig(value) || isPrivateKeyInitializationConfig(value) || isMnemonicInitializationConfig(value)\n}\n\nexport interface AccountInstance {\n readonly address: XyoAddress\n readonly addressBytes: ArrayBufferLike\n readonly algorithm: AccountAlgorithm\n previousHash: Hash | undefined\n previousHashBytes: ArrayBufferLike | undefined\n readonly private?: PrivateKeyInstance\n readonly public?: PublicKeyInstance\n sign: (hash: ArrayBufferLike, previousHash?: ArrayBufferLike) => Promise<[ArrayBufferLike, Hash?]>\n signJwt: (options: SignJwtOptions) => Promise<SignJwtResult>\n verify: (msg: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n}\n\nexport const isAccountInstance = (account: unknown): account is AccountInstance => {\n if (typeof account !== 'object' || account === null) return false\n return typeof (account as { address?: unknown }).address === 'string'\n}\n\nexport interface AccountStatic<T extends AccountInstance = AccountInstance, C extends AccountConfig = AccountConfig> {\n previousHashStore?: PreviousHashStore\n create(options?: C): Promise<T>\n fromPrivateKey(key: ArrayBufferLike | bigint | string): Promise<AccountInstance>\n random(): Promise<AccountInstance>\n}\n", "import { toUint8Array } from '@xylabs/sdk-js'\nimport { tryDecodeQuantAddress } from '@xyo-network/address'\n\nexport function addressTo20Bytes(address: string): ArrayBufferLike {\n const decoded = tryDecodeQuantAddress(address)\n // Quantum (bech32m) address \u2192 its decoded 20-byte payload; otherwise a legacy bare 40-hex address.\n return decoded === undefined ? toUint8Array(address, 20).buffer : decoded.bytes.buffer\n}\n", "import { tryDecodeQuantAddress } from '@xyo-network/address'\n\nexport type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65'\n\n// Single source of truth binding each quantum algorithm to its bech32m HRP (Human-Readable Part).\n// The HRP is what the address prefix communicates: 'qm65' = ML-DSA-65. secp256k1 has no HRP \u2014 its\n// addresses are legacy bare 40-hex strings. To add an algorithm: add a tuple here and register its\n// verifier (see VerifierRegistry).\nconst AlgorithmHrpEntries = [\n ['ml-dsa-65', 'qm65'],\n] as const satisfies readonly (readonly [AccountAlgorithm, string])[]\n\nexport const AccountAlgorithmHrp: Partial<Record<AccountAlgorithm, string>> = Object.fromEntries(AlgorithmHrpEntries)\n\nconst HrpToAlgorithm: Readonly<Record<string, AccountAlgorithm>> = Object.fromEntries(\n AlgorithmHrpEntries.map(([algorithm, hrp]) => [hrp, algorithm]),\n)\n\nexport function hrpForAlgorithm(algorithm: AccountAlgorithm): string | undefined {\n return AccountAlgorithmHrp[algorithm]\n}\n\nexport function algorithmFromAddress(address: string): AccountAlgorithm {\n const decoded = tryDecodeQuantAddress(address)\n // Not a bech32m quantum address \u2192 legacy secp256k1 bare-hex address.\n if (decoded === undefined) return 'secp256k1'\n const algorithm = HrpToAlgorithm[decoded.hrp]\n if (algorithm === undefined) {\n throw new Error(`Unknown address algorithm HRP [${decoded.hrp}]`)\n }\n return algorithm\n}\n", "import { Enum } from '@xylabs/sdk-js'\n\nexport const JwtAlg = Enum({ ES256K: 'ES256K' } as const)\nexport type JwtAlg = Enum<typeof JwtAlg>\n\nexport const JwtTyp = Enum({ JWT: 'JWT' } as const)\nexport type JwtTyp = Enum<typeof JwtTyp>\n\nexport const JwtSchema = Enum({ Signin: 'network.xyo.auth.signin' } as const)\nexport type JwtSchema = Enum<typeof JwtSchema>\n", "import type { AccountAlgorithm } from './Algorithm.ts'\nimport { algorithmFromAddress } from './Algorithm.ts'\n\nexport type VerifySignatureFn = (address: string, hash: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>\n\nconst registry: Partial<Record<AccountAlgorithm, VerifySignatureFn>> = {}\n\nexport function registerVerifier(algorithm: AccountAlgorithm, fn: VerifySignatureFn): void {\n registry[algorithm] = fn\n}\n\nexport function getVerifier(algorithm: AccountAlgorithm): VerifySignatureFn | undefined {\n return registry[algorithm]\n}\n\nexport async function verifySignature(address: string, hash: ArrayBufferLike, signature: ArrayBufferLike): Promise<boolean> {\n const algorithm = algorithmFromAddress(address)\n const fn = registry[algorithm]\n if (!fn) {\n throw new Error(`No verifier registered for algorithm [${algorithm}]. Did you import the account package?`)\n }\n return await fn(address, hash, signature)\n}\n"],
5
+ "mappings": ";AACA,SAAS,qBAAqB;AAQvB,IAAM,mBAAmB;AAoBzB,IAAM,+BAA+B,CAAC,UAAwD;AACnG,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO,OAAQ,MAAqC,WAAW;AAAA,EACjE;AACA,SAAO;AACT;AAEO,IAAM,mCAAmC,CAAC,UAA4D;AAC3G,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO,cAAe,MAAyC,UAAU;AAAA,EAC3E;AACA,SAAO;AACT;AAEO,IAAM,iCAAiC,CAAC,UAA0D;AACvG,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WACE,OAAQ,MAAuC,aAAa,YAAY,QAAS,MAAuC,QAAQ,QAAQ;AAAA,EAE5I;AACA,SAAO;AACT;AAEO,IAAM,yBAAyB,CAAC,UAAkD;AACvF,SAAO,6BAA6B,KAAK,KAAK,iCAAiC,KAAK,KAAK,+BAA+B,KAAK;AAC/H;AAeO,IAAM,oBAAoB,CAAC,YAAiD;AACjF,MAAI,OAAO,YAAY,YAAY,YAAY,KAAM,QAAO;AAC5D,SAAO,OAAQ,QAAkC,YAAY;AAC/D;;;ACxEA,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAE/B,SAAS,iBAAiB,SAAkC;AACjE,QAAM,UAAU,sBAAsB,OAAO;AAE7C,SAAO,YAAY,SAAY,aAAa,SAAS,EAAE,EAAE,SAAS,QAAQ,MAAM;AAClF;;;ACPA,SAAS,yBAAAA,8BAA6B;AAQtC,IAAM,sBAAsB;AAAA,EAC1B,CAAC,aAAa,MAAM;AACtB;AAEO,IAAM,sBAAiE,OAAO,YAAY,mBAAmB;AAEpH,IAAM,iBAA6D,OAAO;AAAA,EACxE,oBAAoB,IAAI,CAAC,CAAC,WAAW,GAAG,MAAM,CAAC,KAAK,SAAS,CAAC;AAChE;AAEO,SAAS,gBAAgB,WAAiD;AAC/E,SAAO,oBAAoB,SAAS;AACtC;AAEO,SAAS,qBAAqB,SAAmC;AACtE,QAAM,UAAUA,uBAAsB,OAAO;AAE7C,MAAI,YAAY,OAAW,QAAO;AAClC,QAAM,YAAY,eAAe,QAAQ,GAAG;AAC5C,MAAI,cAAc,QAAW;AAC3B,UAAM,IAAI,MAAM,kCAAkC,QAAQ,GAAG,GAAG;AAAA,EAClE;AACA,SAAO;AACT;;;AC/BA,SAAS,YAAY;AAEd,IAAM,SAAS,KAAK,EAAE,QAAQ,SAAS,CAAU;AAGjD,IAAM,SAAS,KAAK,EAAE,KAAK,MAAM,CAAU;AAG3C,IAAM,YAAY,KAAK,EAAE,QAAQ,0BAA0B,CAAU;;;ACH5E,IAAM,WAAiE,CAAC;AAEjE,SAAS,iBAAiB,WAA6B,IAA6B;AACzF,WAAS,SAAS,IAAI;AACxB;AAEO,SAAS,YAAY,WAA4D;AACtF,SAAO,SAAS,SAAS;AAC3B;AAEA,eAAsB,gBAAgB,SAAiB,MAAuB,WAA8C;AAC1H,QAAM,YAAY,qBAAqB,OAAO;AAC9C,QAAM,KAAK,SAAS,SAAS;AAC7B,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,yCAAyC,SAAS,wCAAwC;AAAA,EAC5G;AACA,SAAO,MAAM,GAAG,SAAS,MAAM,SAAS;AAC1C;",
6
+ "names": ["tryDecodeQuantAddress"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/account-model",
3
- "version": "6.0.6",
3
+ "version": "6.0.8",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -34,17 +34,17 @@
34
34
  "README.md"
35
35
  ],
36
36
  "dependencies": {
37
- "@xyo-network/key-model": "~6.0.6",
38
- "@xyo-network/address": "~6.0.6",
39
- "@xyo-network/previous-hash-store-model": "~6.0.6"
37
+ "@xyo-network/key-model": "~6.0.8",
38
+ "@xyo-network/previous-hash-store-model": "~6.0.8",
39
+ "@xyo-network/address": "~6.0.8"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@opentelemetry/api": "^1.9.1",
43
43
  "@opentelemetry/sdk-trace-base": "^2.7.1",
44
44
  "@scure/base": "~2.2.0",
45
45
  "@xylabs/sdk-js": "~6.0.6",
46
- "@xylabs/toolchain": "~8.1.8",
47
- "@xylabs/tsconfig": "~8.1.8",
46
+ "@xylabs/toolchain": "~8.1.10",
47
+ "@xylabs/tsconfig": "~8.1.10",
48
48
  "async-mutex": "^0.5.0",
49
49
  "bn.js": "^5.2.3",
50
50
  "buffer": "^6.0.3",