@xyo-network/account-model 6.0.1 → 6.0.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.
Files changed (37) hide show
  1. package/dist/browser/Account.d.ts +2 -0
  2. package/dist/browser/Account.d.ts.map +1 -1
  3. package/dist/browser/Algorithm.d.ts +9 -0
  4. package/dist/browser/Algorithm.d.ts.map +1 -0
  5. package/dist/browser/VerifierRegistry.d.ts +6 -0
  6. package/dist/browser/VerifierRegistry.d.ts.map +1 -0
  7. package/dist/browser/XyoAddress.d.ts +10 -0
  8. package/dist/browser/XyoAddress.d.ts.map +1 -0
  9. package/dist/browser/index.d.ts +3 -0
  10. package/dist/browser/index.d.ts.map +1 -1
  11. package/dist/browser/index.mjs +71 -1
  12. package/dist/browser/index.mjs.map +3 -3
  13. package/dist/neutral/Account.d.ts +2 -0
  14. package/dist/neutral/Account.d.ts.map +1 -1
  15. package/dist/neutral/Algorithm.d.ts +9 -0
  16. package/dist/neutral/Algorithm.d.ts.map +1 -0
  17. package/dist/neutral/VerifierRegistry.d.ts +6 -0
  18. package/dist/neutral/VerifierRegistry.d.ts.map +1 -0
  19. package/dist/neutral/XyoAddress.d.ts +10 -0
  20. package/dist/neutral/XyoAddress.d.ts.map +1 -0
  21. package/dist/neutral/index.d.ts +3 -0
  22. package/dist/neutral/index.d.ts.map +1 -1
  23. package/dist/neutral/index.mjs +71 -1
  24. package/dist/neutral/index.mjs.map +3 -3
  25. package/dist/node/Account.d.ts +2 -0
  26. package/dist/node/Account.d.ts.map +1 -1
  27. package/dist/node/Algorithm.d.ts +9 -0
  28. package/dist/node/Algorithm.d.ts.map +1 -0
  29. package/dist/node/VerifierRegistry.d.ts +6 -0
  30. package/dist/node/VerifierRegistry.d.ts.map +1 -0
  31. package/dist/node/XyoAddress.d.ts +10 -0
  32. package/dist/node/XyoAddress.d.ts.map +1 -0
  33. package/dist/node/index.d.ts +3 -0
  34. package/dist/node/index.d.ts.map +1 -1
  35. package/dist/node/index.mjs +71 -1
  36. package/dist/node/index.mjs.map +3 -3
  37. package/package.json +3 -3
@@ -1,6 +1,7 @@
1
1
  import type { Address, Hash } from '@xylabs/sdk-js';
2
2
  import type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model';
3
3
  import type { PreviousHashStore } from '@xyo-network/previous-hash-store-model';
4
+ import type { AccountAlgorithm } from './Algorithm.ts';
4
5
  import type { SignJwtOptions, SignJwtResult } from './Jwt/types.ts';
5
6
  export declare const ethMessagePrefix = "\u0019Ethereum Signed Message:\n";
6
7
  export interface PhraseInitializationConfig {
@@ -25,6 +26,7 @@ export declare const isInitializationConfig: (value: unknown) => value is Initia
25
26
  export interface AccountInstance {
26
27
  readonly address: Address;
27
28
  readonly addressBytes: ArrayBufferLike;
29
+ readonly algorithm: AccountAlgorithm;
28
30
  previousHash: Hash | undefined;
29
31
  previousHashBytes: ArrayBufferLike | undefined;
30
32
  readonly private?: PrivateKeyInstance;
@@ -1 +1 @@
1
- {"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AACnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAE/E,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnE,eAAO,MAAM,gBAAgB,qCAAqC,CAAA;AAElE,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAA;CACf;AACD,MAAM,WAAW,8BAA8B;IAC7C,UAAU,EAAE,eAAe,CAAA;CAC5B;AACD,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AACD,MAAM,W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C,CAAA;IAC/B,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IAChF,MAAM,IAAI,OAAO,CAAC,eAAe,CAAC,CAAA;CACnC"}
@@ -0,0 +1,9 @@
1
+ export type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65';
2
+ export declare const AccountAlgorithmPrefix: {
3
+ readonly secp256k1: null;
4
+ readonly 'ml-dsa-65': "qr1";
5
+ };
6
+ export declare function algorithmFromAddress(address: string): AccountAlgorithm;
7
+ export declare function stripAddressPrefix(address: string): string;
8
+ export declare function prefixForAlgorithm(algorithm: AccountAlgorithm): string;
9
+ //# sourceMappingURL=Algorithm.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,6 @@
1
+ import type { AccountAlgorithm } from './Algorithm.ts';
2
+ export type VerifySignatureFn = (address: string, hash: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>;
3
+ export declare function registerVerifier(algorithm: AccountAlgorithm, fn: VerifySignatureFn): void;
4
+ export declare function getVerifier(algorithm: AccountAlgorithm): VerifySignatureFn | undefined;
5
+ export declare function verifySignature(address: string, hash: ArrayBufferLike, signature: ArrayBufferLike): Promise<boolean>;
6
+ //# sourceMappingURL=VerifierRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VerifierRegistry.d.ts","sourceRoot":"","sources":["../../src/VerifierRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAGtD,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAIxH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,EAAE,EAAE,EAAE,iBAAiB,GAAG,IAAI,CAEzF;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,gBAAgB,GAAG,iBAAiB,GAAG,SAAS,CAEtF;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAO1H"}
@@ -0,0 +1,10 @@
1
+ import * as z from 'zod/mini';
2
+ export declare const XyoAddressRegEx: RegExp;
3
+ export declare const XyoAddressZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<XyoAddress, string>>;
4
+ export type XyoAddress = string & {
5
+ readonly __xyoAddress: true;
6
+ };
7
+ export declare function isXyoAddress(value: unknown): value is XyoAddress;
8
+ export declare function asXyoAddress(value: unknown): XyoAddress | undefined;
9
+ export declare function addressTo20Bytes(address: string): ArrayBufferLike;
10
+ //# sourceMappingURL=XyoAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XyoAddress.d.ts","sourceRoot":"","sources":["../../src/XyoAddress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAI7B,eAAO,MAAM,eAAe,QAA4B,CAAA;AAExD,eAAO,MAAM,aAAa,gFAGzB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAA;CAAE,CAAA;AAEjE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAInE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAEjE"}
@@ -1,3 +1,6 @@
1
1
  export * from './Account.ts';
2
+ export * from './Algorithm.ts';
2
3
  export * from './Jwt/index.ts';
4
+ export * from './VerifierRegistry.ts';
5
+ export * from './XyoAddress.ts';
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA"}
@@ -26,20 +26,90 @@ var isAccountInstance = (account) => {
26
26
  return typeof account === "object" && typeof account["address"] === "string";
27
27
  };
28
28
 
29
+ // src/Algorithm.ts
30
+ var AccountAlgorithmPrefix = {
31
+ "secp256k1": null,
32
+ "ml-dsa-65": "qr1"
33
+ };
34
+ function algorithmFromAddress(address) {
35
+ const underscore = address.indexOf("_");
36
+ if (underscore === -1) return "secp256k1";
37
+ const prefix = address.slice(0, underscore);
38
+ if (prefix === AccountAlgorithmPrefix["ml-dsa-65"]) return "ml-dsa-65";
39
+ throw new Error(`Unknown address algorithm prefix [${prefix}]`);
40
+ }
41
+ function stripAddressPrefix(address) {
42
+ const underscore = address.indexOf("_");
43
+ return underscore === -1 ? address : address.slice(underscore + 1);
44
+ }
45
+ function prefixForAlgorithm(algorithm) {
46
+ const prefix = AccountAlgorithmPrefix[algorithm];
47
+ return prefix === null ? "" : `${prefix}_`;
48
+ }
49
+
29
50
  // src/Jwt/constants.ts
30
51
  import { Enum } from "@xylabs/sdk-js";
31
52
  var JwtAlg = Enum({ ES256K: "ES256K" });
32
53
  var JwtTyp = Enum({ JWT: "JWT" });
33
54
  var JwtSchema = Enum({ Signin: "network.xyo.auth.signin" });
55
+
56
+ // src/VerifierRegistry.ts
57
+ var registry = {};
58
+ function registerVerifier(algorithm, fn) {
59
+ registry[algorithm] = fn;
60
+ }
61
+ function getVerifier(algorithm) {
62
+ return registry[algorithm];
63
+ }
64
+ async function verifySignature(address, hash, signature) {
65
+ const algorithm = algorithmFromAddress(address);
66
+ const fn = registry[algorithm];
67
+ if (!fn) {
68
+ throw new Error(`No verifier registered for algorithm [${algorithm}]. Did you import the account package?`);
69
+ }
70
+ return await fn(address, hash, signature);
71
+ }
72
+
73
+ // src/XyoAddress.ts
74
+ import { toUint8Array } from "@xylabs/sdk-js";
75
+ import * as z from "zod/mini";
76
+ var XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/;
77
+ var XyoAddressZod = z.pipe(
78
+ z.string().check(z.regex(XyoAddressRegEx)),
79
+ z.transform((s) => s.toLowerCase())
80
+ );
81
+ function isXyoAddress(value) {
82
+ return typeof value === "string" && XyoAddressRegEx.test(value);
83
+ }
84
+ function asXyoAddress(value) {
85
+ if (typeof value !== "string") return void 0;
86
+ const lowered = value.toLowerCase();
87
+ return XyoAddressRegEx.test(lowered) ? lowered : void 0;
88
+ }
89
+ function addressTo20Bytes(address) {
90
+ return toUint8Array(stripAddressPrefix(address), 20).buffer;
91
+ }
34
92
  export {
93
+ AccountAlgorithmPrefix,
35
94
  JwtAlg,
36
95
  JwtSchema,
37
96
  JwtTyp,
97
+ XyoAddressRegEx,
98
+ XyoAddressZod,
99
+ addressTo20Bytes,
100
+ algorithmFromAddress,
101
+ asXyoAddress,
38
102
  ethMessagePrefix,
103
+ getVerifier,
39
104
  isAccountInstance,
40
105
  isInitializationConfig,
41
106
  isMnemonicInitializationConfig,
42
107
  isPhraseInitializationConfig,
43
- isPrivateKeyInitializationConfig
108
+ isPrivateKeyInitializationConfig,
109
+ isXyoAddress,
110
+ prefixForAlgorithm,
111
+ registerVerifier,
112
+ stripAddressPrefix,
113
+ verifySignature
44
114
  };
45
115
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/Account.ts", "../../src/Jwt/constants.ts"],
4
- "sourcesContent": ["import type { Address, Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\nimport type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model'\nimport type { PreviousHashStore } from '@xyo-network/previous-hash-store-model'\n\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: Address\n readonly addressBytes: ArrayBufferLike\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\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isAccountInstance = (account: any): account is AccountInstance => {\n return typeof account === 'object' && typeof account['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 { 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"],
5
- "mappings": ";AACA,SAAS,qBAAqB;AAMvB,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,YAA6C;AAC7E,SAAO,OAAO,YAAY,YAAY,OAAO,QAAQ,SAAS,MAAM;AACtE;;;ACrEA,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;",
3
+ "sources": ["../../src/Account.ts", "../../src/Algorithm.ts", "../../src/Jwt/constants.ts", "../../src/VerifierRegistry.ts", "../../src/XyoAddress.ts"],
4
+ "sourcesContent": ["import type { Address, Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\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: Address\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\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isAccountInstance = (account: any): account is AccountInstance => {\n return typeof account === 'object' && typeof account['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", "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", "import { toUint8Array } from '@xylabs/sdk-js'\nimport * as z from 'zod/mini'\n\nimport { stripAddressPrefix } from './Algorithm.ts'\n\nexport const XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/\n\nexport const XyoAddressZod = z.pipe(\n z.string().check(z.regex(XyoAddressRegEx)),\n z.transform(s => s.toLowerCase() as XyoAddress),\n)\n\nexport type XyoAddress = string & { readonly __xyoAddress: true }\n\nexport function isXyoAddress(value: unknown): value is XyoAddress {\n return typeof value === 'string' && XyoAddressRegEx.test(value)\n}\n\nexport function asXyoAddress(value: unknown): XyoAddress | undefined {\n if (typeof value !== 'string') return undefined\n const lowered = value.toLowerCase()\n return XyoAddressRegEx.test(lowered) ? (lowered as XyoAddress) : undefined\n}\n\nexport function addressTo20Bytes(address: string): ArrayBufferLike {\n return toUint8Array(stripAddressPrefix(address), 20).buffer\n}\n"],
5
+ "mappings": ";AACA,SAAS,qBAAqB;AAOvB,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;AAgBO,IAAM,oBAAoB,CAAC,YAA6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AkB;AAExB,IAAM,gBAAkB;AAAA,EAC3B,SAAO,EAAE,MAAQ,QAAM,eAAe,CAAC;AAAA,EACvC,YAAU,OAAK,EAAE,YAAY,CAAe;AAChD;AAIO,SAAS,aAAa,OAAqC;AAChE,SAAO,OAAO,UAAU,YAAY,gBAAgB,KAAK,KAAK;AAChE;AAEO,SAAS,aAAa,OAAwC;AACnE,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAM,UAAU,MAAM,YAAY;AAClC,SAAO,gBAAgB,KAAK,OAAO,IAAK,UAAyB;AACnE;AAEO,SAAS,iBAAiB,SAAkC;AACjE,SAAO,aAAa,mBAAmB,OAAO,GAAG,EAAE,EAAE;AACvD;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,7 @@
1
1
  import type { Address, Hash } from '@xylabs/sdk-js';
2
2
  import type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model';
3
3
  import type { PreviousHashStore } from '@xyo-network/previous-hash-store-model';
4
+ import type { AccountAlgorithm } from './Algorithm.ts';
4
5
  import type { SignJwtOptions, SignJwtResult } from './Jwt/types.ts';
5
6
  export declare const ethMessagePrefix = "\u0019Ethereum Signed Message:\n";
6
7
  export interface PhraseInitializationConfig {
@@ -25,6 +26,7 @@ export declare const isInitializationConfig: (value: unknown) => value is Initia
25
26
  export interface AccountInstance {
26
27
  readonly address: Address;
27
28
  readonly addressBytes: ArrayBufferLike;
29
+ readonly algorithm: AccountAlgorithm;
28
30
  previousHash: Hash | undefined;
29
31
  previousHashBytes: ArrayBufferLike | undefined;
30
32
  readonly private?: PrivateKeyInstance;
@@ -1 +1 @@
1
- {"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AACnF,OAAO,KAAK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C5D,MAAM,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC/E;AAGD,eAAO,MAAM,iBAAiB,GAAI,SAAS,GAAG,KAAG,OAAO,IAAI,eAE3D,CAAA;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,EAAE,CAAC,SAAS,aAAa,GAAG,aAAa;IACjH,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;IACrC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IAC/B,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IAChF,MAAM,IAAI,OAAO,CAAC,eAAe,CAAC,CAAA;CACnC"}
@@ -0,0 +1,9 @@
1
+ export type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65';
2
+ export declare const AccountAlgorithmPrefix: {
3
+ readonly secp256k1: null;
4
+ readonly 'ml-dsa-65': "qr1";
5
+ };
6
+ export declare function algorithmFromAddress(address: string): AccountAlgorithm;
7
+ export declare function stripAddressPrefix(address: string): string;
8
+ export declare function prefixForAlgorithm(algorithm: AccountAlgorithm): string;
9
+ //# sourceMappingURL=Algorithm.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,6 @@
1
+ import type { AccountAlgorithm } from './Algorithm.ts';
2
+ export type VerifySignatureFn = (address: string, hash: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>;
3
+ export declare function registerVerifier(algorithm: AccountAlgorithm, fn: VerifySignatureFn): void;
4
+ export declare function getVerifier(algorithm: AccountAlgorithm): VerifySignatureFn | undefined;
5
+ export declare function verifySignature(address: string, hash: ArrayBufferLike, signature: ArrayBufferLike): Promise<boolean>;
6
+ //# sourceMappingURL=VerifierRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VerifierRegistry.d.ts","sourceRoot":"","sources":["../../src/VerifierRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAGtD,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAIxH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,EAAE,EAAE,EAAE,iBAAiB,GAAG,IAAI,CAEzF;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,gBAAgB,GAAG,iBAAiB,GAAG,SAAS,CAEtF;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAO1H"}
@@ -0,0 +1,10 @@
1
+ import * as z from 'zod/mini';
2
+ export declare const XyoAddressRegEx: RegExp;
3
+ export declare const XyoAddressZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<XyoAddress, string>>;
4
+ export type XyoAddress = string & {
5
+ readonly __xyoAddress: true;
6
+ };
7
+ export declare function isXyoAddress(value: unknown): value is XyoAddress;
8
+ export declare function asXyoAddress(value: unknown): XyoAddress | undefined;
9
+ export declare function addressTo20Bytes(address: string): ArrayBufferLike;
10
+ //# sourceMappingURL=XyoAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XyoAddress.d.ts","sourceRoot":"","sources":["../../src/XyoAddress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAI7B,eAAO,MAAM,eAAe,QAA4B,CAAA;AAExD,eAAO,MAAM,aAAa,gFAGzB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAA;CAAE,CAAA;AAEjE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAInE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAEjE"}
@@ -1,3 +1,6 @@
1
1
  export * from './Account.ts';
2
+ export * from './Algorithm.ts';
2
3
  export * from './Jwt/index.ts';
4
+ export * from './VerifierRegistry.ts';
5
+ export * from './XyoAddress.ts';
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA"}
@@ -26,20 +26,90 @@ var isAccountInstance = (account) => {
26
26
  return typeof account === "object" && typeof account["address"] === "string";
27
27
  };
28
28
 
29
+ // src/Algorithm.ts
30
+ var AccountAlgorithmPrefix = {
31
+ "secp256k1": null,
32
+ "ml-dsa-65": "qr1"
33
+ };
34
+ function algorithmFromAddress(address) {
35
+ const underscore = address.indexOf("_");
36
+ if (underscore === -1) return "secp256k1";
37
+ const prefix = address.slice(0, underscore);
38
+ if (prefix === AccountAlgorithmPrefix["ml-dsa-65"]) return "ml-dsa-65";
39
+ throw new Error(`Unknown address algorithm prefix [${prefix}]`);
40
+ }
41
+ function stripAddressPrefix(address) {
42
+ const underscore = address.indexOf("_");
43
+ return underscore === -1 ? address : address.slice(underscore + 1);
44
+ }
45
+ function prefixForAlgorithm(algorithm) {
46
+ const prefix = AccountAlgorithmPrefix[algorithm];
47
+ return prefix === null ? "" : `${prefix}_`;
48
+ }
49
+
29
50
  // src/Jwt/constants.ts
30
51
  import { Enum } from "@xylabs/sdk-js";
31
52
  var JwtAlg = Enum({ ES256K: "ES256K" });
32
53
  var JwtTyp = Enum({ JWT: "JWT" });
33
54
  var JwtSchema = Enum({ Signin: "network.xyo.auth.signin" });
55
+
56
+ // src/VerifierRegistry.ts
57
+ var registry = {};
58
+ function registerVerifier(algorithm, fn) {
59
+ registry[algorithm] = fn;
60
+ }
61
+ function getVerifier(algorithm) {
62
+ return registry[algorithm];
63
+ }
64
+ async function verifySignature(address, hash, signature) {
65
+ const algorithm = algorithmFromAddress(address);
66
+ const fn = registry[algorithm];
67
+ if (!fn) {
68
+ throw new Error(`No verifier registered for algorithm [${algorithm}]. Did you import the account package?`);
69
+ }
70
+ return await fn(address, hash, signature);
71
+ }
72
+
73
+ // src/XyoAddress.ts
74
+ import { toUint8Array } from "@xylabs/sdk-js";
75
+ import * as z from "zod/mini";
76
+ var XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/;
77
+ var XyoAddressZod = z.pipe(
78
+ z.string().check(z.regex(XyoAddressRegEx)),
79
+ z.transform((s) => s.toLowerCase())
80
+ );
81
+ function isXyoAddress(value) {
82
+ return typeof value === "string" && XyoAddressRegEx.test(value);
83
+ }
84
+ function asXyoAddress(value) {
85
+ if (typeof value !== "string") return void 0;
86
+ const lowered = value.toLowerCase();
87
+ return XyoAddressRegEx.test(lowered) ? lowered : void 0;
88
+ }
89
+ function addressTo20Bytes(address) {
90
+ return toUint8Array(stripAddressPrefix(address), 20).buffer;
91
+ }
34
92
  export {
93
+ AccountAlgorithmPrefix,
35
94
  JwtAlg,
36
95
  JwtSchema,
37
96
  JwtTyp,
97
+ XyoAddressRegEx,
98
+ XyoAddressZod,
99
+ addressTo20Bytes,
100
+ algorithmFromAddress,
101
+ asXyoAddress,
38
102
  ethMessagePrefix,
103
+ getVerifier,
39
104
  isAccountInstance,
40
105
  isInitializationConfig,
41
106
  isMnemonicInitializationConfig,
42
107
  isPhraseInitializationConfig,
43
- isPrivateKeyInitializationConfig
108
+ isPrivateKeyInitializationConfig,
109
+ isXyoAddress,
110
+ prefixForAlgorithm,
111
+ registerVerifier,
112
+ stripAddressPrefix,
113
+ verifySignature
44
114
  };
45
115
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/Account.ts", "../../src/Jwt/constants.ts"],
4
- "sourcesContent": ["import type { Address, Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\nimport type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model'\nimport type { PreviousHashStore } from '@xyo-network/previous-hash-store-model'\n\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: Address\n readonly addressBytes: ArrayBufferLike\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\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isAccountInstance = (account: any): account is AccountInstance => {\n return typeof account === 'object' && typeof account['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 { 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"],
5
- "mappings": ";AACA,SAAS,qBAAqB;AAMvB,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,YAA6C;AAC7E,SAAO,OAAO,YAAY,YAAY,OAAO,QAAQ,SAAS,MAAM;AACtE;;;ACrEA,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;",
3
+ "sources": ["../../src/Account.ts", "../../src/Algorithm.ts", "../../src/Jwt/constants.ts", "../../src/VerifierRegistry.ts", "../../src/XyoAddress.ts"],
4
+ "sourcesContent": ["import type { Address, Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\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: Address\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\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isAccountInstance = (account: any): account is AccountInstance => {\n return typeof account === 'object' && typeof account['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", "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", "import { toUint8Array } from '@xylabs/sdk-js'\nimport * as z from 'zod/mini'\n\nimport { stripAddressPrefix } from './Algorithm.ts'\n\nexport const XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/\n\nexport const XyoAddressZod = z.pipe(\n z.string().check(z.regex(XyoAddressRegEx)),\n z.transform(s => s.toLowerCase() as XyoAddress),\n)\n\nexport type XyoAddress = string & { readonly __xyoAddress: true }\n\nexport function isXyoAddress(value: unknown): value is XyoAddress {\n return typeof value === 'string' && XyoAddressRegEx.test(value)\n}\n\nexport function asXyoAddress(value: unknown): XyoAddress | undefined {\n if (typeof value !== 'string') return undefined\n const lowered = value.toLowerCase()\n return XyoAddressRegEx.test(lowered) ? (lowered as XyoAddress) : undefined\n}\n\nexport function addressTo20Bytes(address: string): ArrayBufferLike {\n return toUint8Array(stripAddressPrefix(address), 20).buffer\n}\n"],
5
+ "mappings": ";AACA,SAAS,qBAAqB;AAOvB,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,Y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B;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;;;ACtBA,SAAS,oBAAoB;AAC7B,YAAY,OAAO;AAIZ,IAAM,kBAAkB;AAExB,IAAM,gBAAkB;AAAA,EAC3B,SAAO,EAAE,MAAQ,QAAM,eAAe,CAAC;AAAA,EACvC,YAAU,OAAK,EAAE,YAAY,CAAe;AAChD;AAIO,SAAS,aAAa,OAAqC;AAChE,SAAO,OAAO,UAAU,YAAY,gBAAgB,KAAK,KAAK;AAChE;AAEO,SAAS,aAAa,OAAwC;AACnE,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAM,UAAU,MAAM,YAAY;AAClC,SAAO,gBAAgB,KAAK,OAAO,IAAK,UAAyB;AACnE;AAEO,SAAS,iBAAiB,SAAkC;AACjE,SAAO,aAAa,mBAAmB,OAAO,GAAG,EAAE,EAAE;AACvD;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,7 @@
1
1
  import type { Address, Hash } from '@xylabs/sdk-js';
2
2
  import type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model';
3
3
  import type { PreviousHashStore } from '@xyo-network/previous-hash-store-model';
4
+ import type { AccountAlgorithm } from './Algorithm.ts';
4
5
  import type { SignJwtOptions, SignJwtResult } from './Jwt/types.ts';
5
6
  export declare const ethMessagePrefix = "\u0019Ethereum Signed Message:\n";
6
7
  export interface PhraseInitializationConfig {
@@ -25,6 +26,7 @@ export declare const isInitializationConfig: (value: unknown) => value is Initia
25
26
  export interface AccountInstance {
26
27
  readonly address: Address;
27
28
  readonly addressBytes: ArrayBufferLike;
29
+ readonly algorithm: AccountAlgorithm;
28
30
  previousHash: Hash | undefined;
29
31
  previousHashBytes: ArrayBufferLike | undefined;
30
32
  readonly private?: PrivateKeyInstance;
@@ -1 +1 @@
1
- {"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../../src/Account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AACnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAE/E,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnE,eAAO,MAAM,gBAAgB,qCAAqC,CAAA;AAElE,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAA;CACf;AACD,MAAM,WAAW,8BAA8B;IAC7C,UAAU,EAAE,eAAe,CAAA;CAC5B;AACD,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AACD,MAAM,WAAW,cAAc;IAC7B,YAAY,CAAC,EAAE,eAAe,CAAA;CAC/B;AAED,MAAM,MAAM,oBAAoB,GAAG,0BAA0B,GAAG,8BAA8B,GAAG,4BAA4B,CAAA;AAE7H,MAAM,MAAM,aAAa,GAAG,oBAAoB,GAAG,cAAc,CAAA;AAEjE,eAAO,MAAM,4BAA4B,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,0BAKtE,CAAA;AAED,eAAO,MAAM,gCAAgC,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,8BAK1E,CAAA;AAED,eAAO,MAAM,8BAA8B,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,4BAOxE,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,OAA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I,GAAG,SAAS,CAAA;IAC9B,iBAAiB,EAAE,eAAe,GAAG,SAAS,CAAA;IAC9C,QAAQ,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAA;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,iBAAiB,CAAA;IACnC,IAAI,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,YAAY,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IAClG,OAAO,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,aAAa,CAAC,CAAA;IAC5D,MAAM,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC/E;AAGD,eAAO,MAAM,iBAAiB,GAAI,SAAS,GAAG,KAAG,OAAO,IAAI,eAE3D,CAAA;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,EAAE,CAAC,SAAS,aAAa,GAAG,aAAa;IACjH,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;IACrC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IAC/B,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IAChF,MAAM,IAAI,OAAO,CAAC,eAAe,CAAC,CAAA;CACnC"}
@@ -0,0 +1,9 @@
1
+ export type AccountAlgorithm = 'secp256k1' | 'ml-dsa-65';
2
+ export declare const AccountAlgorithmPrefix: {
3
+ readonly secp256k1: null;
4
+ readonly 'ml-dsa-65': "qr1";
5
+ };
6
+ export declare function algorithmFromAddress(address: string): AccountAlgorithm;
7
+ export declare function stripAddressPrefix(address: string): string;
8
+ export declare function prefixForAlgorithm(algorithm: AccountAlgorithm): string;
9
+ //# sourceMappingURL=Algorithm.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,6 @@
1
+ import type { AccountAlgorithm } from './Algorithm.ts';
2
+ export type VerifySignatureFn = (address: string, hash: ArrayBufferLike, signature: ArrayBufferLike) => Promise<boolean>;
3
+ export declare function registerVerifier(algorithm: AccountAlgorithm, fn: VerifySignatureFn): void;
4
+ export declare function getVerifier(algorithm: AccountAlgorithm): VerifySignatureFn | undefined;
5
+ export declare function verifySignature(address: string, hash: ArrayBufferLike, signature: ArrayBufferLike): Promise<boolean>;
6
+ //# sourceMappingURL=VerifierRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VerifierRegistry.d.ts","sourceRoot":"","sources":["../../src/VerifierRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAGtD,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAIxH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,EAAE,EAAE,EAAE,iBAAiB,GAAG,IAAI,CAEzF;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,gBAAgB,GAAG,iBAAiB,GAAG,SAAS,CAEtF;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAO1H"}
@@ -0,0 +1,10 @@
1
+ import * as z from 'zod/mini';
2
+ export declare const XyoAddressRegEx: RegExp;
3
+ export declare const XyoAddressZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<XyoAddress, string>>;
4
+ export type XyoAddress = string & {
5
+ readonly __xyoAddress: true;
6
+ };
7
+ export declare function isXyoAddress(value: unknown): value is XyoAddress;
8
+ export declare function asXyoAddress(value: unknown): XyoAddress | undefined;
9
+ export declare function addressTo20Bytes(address: string): ArrayBufferLike;
10
+ //# sourceMappingURL=XyoAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XyoAddress.d.ts","sourceRoot":"","sources":["../../src/XyoAddress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAI7B,eAAO,MAAM,eAAe,QAA4B,CAAA;AAExD,eAAO,MAAM,aAAa,gFAGzB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAA;CAAE,CAAA;AAEjE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAInE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAEjE"}
@@ -1,3 +1,6 @@
1
1
  export * from './Account.ts';
2
+ export * from './Algorithm.ts';
2
3
  export * from './Jwt/index.ts';
4
+ export * from './VerifierRegistry.ts';
5
+ export * from './XyoAddress.ts';
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA"}
@@ -26,20 +26,90 @@ var isAccountInstance = (account) => {
26
26
  return typeof account === "object" && typeof account["address"] === "string";
27
27
  };
28
28
 
29
+ // src/Algorithm.ts
30
+ var AccountAlgorithmPrefix = {
31
+ "secp256k1": null,
32
+ "ml-dsa-65": "qr1"
33
+ };
34
+ function algorithmFromAddress(address) {
35
+ const underscore = address.indexOf("_");
36
+ if (underscore === -1) return "secp256k1";
37
+ const prefix = address.slice(0, underscore);
38
+ if (prefix === AccountAlgorithmPrefix["ml-dsa-65"]) return "ml-dsa-65";
39
+ throw new Error(`Unknown address algorithm prefix [${prefix}]`);
40
+ }
41
+ function stripAddressPrefix(address) {
42
+ const underscore = address.indexOf("_");
43
+ return underscore === -1 ? address : address.slice(underscore + 1);
44
+ }
45
+ function prefixForAlgorithm(algorithm) {
46
+ const prefix = AccountAlgorithmPrefix[algorithm];
47
+ return prefix === null ? "" : `${prefix}_`;
48
+ }
49
+
29
50
  // src/Jwt/constants.ts
30
51
  import { Enum } from "@xylabs/sdk-js";
31
52
  var JwtAlg = Enum({ ES256K: "ES256K" });
32
53
  var JwtTyp = Enum({ JWT: "JWT" });
33
54
  var JwtSchema = Enum({ Signin: "network.xyo.auth.signin" });
55
+
56
+ // src/VerifierRegistry.ts
57
+ var registry = {};
58
+ function registerVerifier(algorithm, fn) {
59
+ registry[algorithm] = fn;
60
+ }
61
+ function getVerifier(algorithm) {
62
+ return registry[algorithm];
63
+ }
64
+ async function verifySignature(address, hash, signature) {
65
+ const algorithm = algorithmFromAddress(address);
66
+ const fn = registry[algorithm];
67
+ if (!fn) {
68
+ throw new Error(`No verifier registered for algorithm [${algorithm}]. Did you import the account package?`);
69
+ }
70
+ return await fn(address, hash, signature);
71
+ }
72
+
73
+ // src/XyoAddress.ts
74
+ import { toUint8Array } from "@xylabs/sdk-js";
75
+ import * as z from "zod/mini";
76
+ var XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/;
77
+ var XyoAddressZod = z.pipe(
78
+ z.string().check(z.regex(XyoAddressRegEx)),
79
+ z.transform((s) => s.toLowerCase())
80
+ );
81
+ function isXyoAddress(value) {
82
+ return typeof value === "string" && XyoAddressRegEx.test(value);
83
+ }
84
+ function asXyoAddress(value) {
85
+ if (typeof value !== "string") return void 0;
86
+ const lowered = value.toLowerCase();
87
+ return XyoAddressRegEx.test(lowered) ? lowered : void 0;
88
+ }
89
+ function addressTo20Bytes(address) {
90
+ return toUint8Array(stripAddressPrefix(address), 20).buffer;
91
+ }
34
92
  export {
93
+ AccountAlgorithmPrefix,
35
94
  JwtAlg,
36
95
  JwtSchema,
37
96
  JwtTyp,
97
+ XyoAddressRegEx,
98
+ XyoAddressZod,
99
+ addressTo20Bytes,
100
+ algorithmFromAddress,
101
+ asXyoAddress,
38
102
  ethMessagePrefix,
103
+ getVerifier,
39
104
  isAccountInstance,
40
105
  isInitializationConfig,
41
106
  isMnemonicInitializationConfig,
42
107
  isPhraseInitializationConfig,
43
- isPrivateKeyInitializationConfig
108
+ isPrivateKeyInitializationConfig,
109
+ isXyoAddress,
110
+ prefixForAlgorithm,
111
+ registerVerifier,
112
+ stripAddressPrefix,
113
+ verifySignature
44
114
  };
45
115
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/Account.ts", "../../src/Jwt/constants.ts"],
4
- "sourcesContent": ["import type { Address, Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\nimport type { PrivateKeyInstance, PublicKeyInstance } from '@xyo-network/key-model'\nimport type { PreviousHashStore } from '@xyo-network/previous-hash-store-model'\n\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: Address\n readonly addressBytes: ArrayBufferLike\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\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isAccountInstance = (account: any): account is AccountInstance => {\n return typeof account === 'object' && typeof account['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 { 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"],
5
- "mappings": ";AACA,SAAS,qBAAqB;AAMvB,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,YAA6C;AAC7E,SAAO,OAAO,YAAY,YAAY,OAAO,QAAQ,SAAS,MAAM;AACtE;;;ACrEA,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;",
3
+ "sources": ["../../src/Account.ts", "../../src/Algorithm.ts", "../../src/Jwt/constants.ts", "../../src/VerifierRegistry.ts", "../../src/XyoAddress.ts"],
4
+ "sourcesContent": ["import type { Address, Hash } from '@xylabs/sdk-js'\nimport { isArrayBuffer } from '@xylabs/sdk-js'\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: Address\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\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isAccountInstance = (account: any): account is AccountInstance => {\n return typeof account === 'object' && typeof account['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", "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", "import { toUint8Array } from '@xylabs/sdk-js'\nimport * as z from 'zod/mini'\n\nimport { stripAddressPrefix } from './Algorithm.ts'\n\nexport const XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/\n\nexport const XyoAddressZod = z.pipe(\n z.string().check(z.regex(XyoAddressRegEx)),\n z.transform(s => s.toLowerCase() as XyoAddress),\n)\n\nexport type XyoAddress = string & { readonly __xyoAddress: true }\n\nexport function isXyoAddress(value: unknown): value is XyoAddress {\n return typeof value === 'string' && XyoAddressRegEx.test(value)\n}\n\nexport function asXyoAddress(value: unknown): XyoAddress | undefined {\n if (typeof value !== 'string') return undefined\n const lowered = value.toLowerCase()\n return XyoAddressRegEx.test(lowered) ? (lowered as XyoAddress) : undefined\n}\n\nexport function addressTo20Bytes(address: string): ArrayBufferLike {\n return toUint8Array(stripAddressPrefix(address), 20).buffer\n}\n"],
5
+ "mappings": ";AACA,SAAS,qBAAqB;AAOvB,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;AAgBO,IAAM,oBAAoB,CAAC,YAA6C;AAC7E,SAAO,OAAO,YAAY,YAAY,OAAO,QAAQ,SAAS,MAAM;AACtE;;;ACrEO,IAAM,yBAAyB;AAAA,EACpC,aAAa;AAAA,EACb,aAAa;AACf;AAEO,SAAS,qBAAqB,SAAmC;AACtE,QAAM,aAAa,QAAQ,QAAQ,GAAG;AAEtC,MAAI,eAAe,GAAI,QAAO;AAC9B,QAAM,SAAS,QAAQ,MAAM,GAAG,UAAU;AAC1C,MAAI,WAAW,uBAAuB,WAAW,EAAG,QAAO;AAC3D,QAAM,IAAI,MAAM,qCAAqC,MAAM,GAAG;AAChE;AAEO,SAAS,mBAAmB,SAAyB;AAC1D,QAAM,aAAa,QAAQ,QAAQ,GAAG;AACtC,SAAO,eAAe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  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/account-model",
3
- "version": "6.0.1",
3
+ "version": "6.0.3",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -34,8 +34,8 @@
34
34
  "README.md"
35
35
  ],
36
36
  "dependencies": {
37
- "@xyo-network/previous-hash-store-model": "~6.0.1",
38
- "@xyo-network/key-model": "~6.0.1"
37
+ "@xyo-network/previous-hash-store-model": "~6.0.3",
38
+ "@xyo-network/key-model": "~6.0.3"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@opentelemetry/api": "^1.9.1",