@xyo-network/account-model 6.0.2 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/Account.d.ts +2 -0
- package/dist/browser/Account.d.ts.map +1 -1
- package/dist/browser/Algorithm.d.ts +9 -0
- package/dist/browser/Algorithm.d.ts.map +1 -0
- package/dist/browser/VerifierRegistry.d.ts +6 -0
- package/dist/browser/VerifierRegistry.d.ts.map +1 -0
- package/dist/browser/XyoAddress.d.ts +12 -0
- package/dist/browser/XyoAddress.d.ts.map +1 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.mjs +70 -1
- package/dist/browser/index.mjs.map +3 -3
- package/dist/neutral/Account.d.ts +2 -0
- package/dist/neutral/Account.d.ts.map +1 -1
- package/dist/neutral/Algorithm.d.ts +9 -0
- package/dist/neutral/Algorithm.d.ts.map +1 -0
- package/dist/neutral/VerifierRegistry.d.ts +6 -0
- package/dist/neutral/VerifierRegistry.d.ts.map +1 -0
- package/dist/neutral/XyoAddress.d.ts +12 -0
- package/dist/neutral/XyoAddress.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +3 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +70 -1
- package/dist/neutral/index.mjs.map +3 -3
- package/dist/node/Account.d.ts +2 -0
- package/dist/node/Account.d.ts.map +1 -1
- package/dist/node/Algorithm.d.ts +9 -0
- package/dist/node/Algorithm.d.ts.map +1 -0
- package/dist/node/VerifierRegistry.d.ts +6 -0
- package/dist/node/VerifierRegistry.d.ts.map +1 -0
- package/dist/node/XyoAddress.d.ts +12 -0
- package/dist/node/XyoAddress.d.ts.map +1 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.mjs +70 -1
- package/dist/node/index.mjs.map +3 -3
- 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;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AO,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,12 @@
|
|
|
1
|
+
import type * as z from 'zod/mini';
|
|
2
|
+
export declare const XyoAddressRegEx: RegExp;
|
|
3
|
+
export declare const XyoAddressZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<Lowercase<string> & {
|
|
4
|
+
readonly __hex: true;
|
|
5
|
+
} & {
|
|
6
|
+
readonly __address: true;
|
|
7
|
+
}, string>>;
|
|
8
|
+
export type XyoAddress = z.infer<typeof XyoAddressZod>;
|
|
9
|
+
export declare function isXyoAddress(value: unknown): value is XyoAddress;
|
|
10
|
+
export declare function asXyoAddress(value: unknown): XyoAddress | undefined;
|
|
11
|
+
export declare function addressTo20Bytes(address: string): ArrayBufferLike;
|
|
12
|
+
//# sourceMappingURL=XyoAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XyoAddress.d.ts","sourceRoot":"","sources":["../../src/XyoAddress.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,CAAC,MAAM,UAAU,CAAA;AAIlC,eAAO,MAAM,eAAe,QAA4B,CAAA;AAExD,eAAO,MAAM,aAAa;;;;WAAa,CAAA;AAEvC,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AAEtD,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAEnE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAEjE"}
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -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"}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -26,20 +26,89 @@ 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 {
|
|
75
|
+
AddressZod,
|
|
76
|
+
asAddress,
|
|
77
|
+
isAddress,
|
|
78
|
+
toUint8Array
|
|
79
|
+
} from "@xylabs/sdk-js";
|
|
80
|
+
var XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/;
|
|
81
|
+
var XyoAddressZod = AddressZod;
|
|
82
|
+
function isXyoAddress(value) {
|
|
83
|
+
return isAddress(value);
|
|
84
|
+
}
|
|
85
|
+
function asXyoAddress(value) {
|
|
86
|
+
return asAddress(value);
|
|
87
|
+
}
|
|
88
|
+
function addressTo20Bytes(address) {
|
|
89
|
+
return toUint8Array(stripAddressPrefix(address), 20).buffer;
|
|
90
|
+
}
|
|
34
91
|
export {
|
|
92
|
+
AccountAlgorithmPrefix,
|
|
35
93
|
JwtAlg,
|
|
36
94
|
JwtSchema,
|
|
37
95
|
JwtTyp,
|
|
96
|
+
XyoAddressRegEx,
|
|
97
|
+
XyoAddressZod,
|
|
98
|
+
addressTo20Bytes,
|
|
99
|
+
algorithmFromAddress,
|
|
100
|
+
asXyoAddress,
|
|
38
101
|
ethMessagePrefix,
|
|
102
|
+
getVerifier,
|
|
39
103
|
isAccountInstance,
|
|
40
104
|
isInitializationConfig,
|
|
41
105
|
isMnemonicInitializationConfig,
|
|
42
106
|
isPhraseInitializationConfig,
|
|
43
|
-
isPrivateKeyInitializationConfig
|
|
107
|
+
isPrivateKeyInitializationConfig,
|
|
108
|
+
isXyoAddress,
|
|
109
|
+
prefixForAlgorithm,
|
|
110
|
+
registerVerifier,
|
|
111
|
+
stripAddressPrefix,
|
|
112
|
+
verifySignature
|
|
44
113
|
};
|
|
45
114
|
//# 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;
|
|
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 {\n AddressZod, asAddress, isAddress, toUint8Array,\n} from '@xylabs/sdk-js'\nimport type * as z from 'zod/mini'\n\nimport { stripAddressPrefix } from './Algorithm.ts'\n\nexport const XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/\n\nexport const XyoAddressZod = AddressZod\n\nexport type XyoAddress = z.infer<typeof XyoAddressZod>\n\nexport function isXyoAddress(value: unknown): value is XyoAddress {\n return isAddress(value)\n}\n\nexport function asXyoAddress(value: unknown): XyoAddress | undefined {\n return asAddress(value)\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,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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,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e,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,12 @@
|
|
|
1
|
+
import type * as z from 'zod/mini';
|
|
2
|
+
export declare const XyoAddressRegEx: RegExp;
|
|
3
|
+
export declare const XyoAddressZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<Lowercase<string> & {
|
|
4
|
+
readonly __hex: true;
|
|
5
|
+
} & {
|
|
6
|
+
readonly __address: true;
|
|
7
|
+
}, string>>;
|
|
8
|
+
export type XyoAddress = z.infer<typeof XyoAddressZod>;
|
|
9
|
+
export declare function isXyoAddress(value: unknown): value is XyoAddress;
|
|
10
|
+
export declare function asXyoAddress(value: unknown): XyoAddress | undefined;
|
|
11
|
+
export declare function addressTo20Bytes(address: string): ArrayBufferLike;
|
|
12
|
+
//# sourceMappingURL=XyoAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XyoAddress.d.ts","sourceRoot":"","sources":["../../src/XyoAddress.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,CAAC,MAAM,UAAU,CAAA;AAIlC,eAAO,MAAM,eAAe,QAA4B,CAAA;AAExD,eAAO,MAAM,aAAa;;;;WAAa,CAAA;AAEvC,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AAEtD,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAEnE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAEjE"}
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -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"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -26,20 +26,89 @@ 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 {
|
|
75
|
+
AddressZod,
|
|
76
|
+
asAddress,
|
|
77
|
+
isAddress,
|
|
78
|
+
toUint8Array
|
|
79
|
+
} from "@xylabs/sdk-js";
|
|
80
|
+
var XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/;
|
|
81
|
+
var XyoAddressZod = AddressZod;
|
|
82
|
+
function isXyoAddress(value) {
|
|
83
|
+
return isAddress(value);
|
|
84
|
+
}
|
|
85
|
+
function asXyoAddress(value) {
|
|
86
|
+
return asAddress(value);
|
|
87
|
+
}
|
|
88
|
+
function addressTo20Bytes(address) {
|
|
89
|
+
return toUint8Array(stripAddressPrefix(address), 20).buffer;
|
|
90
|
+
}
|
|
34
91
|
export {
|
|
92
|
+
AccountAlgorithmPrefix,
|
|
35
93
|
JwtAlg,
|
|
36
94
|
JwtSchema,
|
|
37
95
|
JwtTyp,
|
|
96
|
+
XyoAddressRegEx,
|
|
97
|
+
XyoAddressZod,
|
|
98
|
+
addressTo20Bytes,
|
|
99
|
+
algorithmFromAddress,
|
|
100
|
+
asXyoAddress,
|
|
38
101
|
ethMessagePrefix,
|
|
102
|
+
getVerifier,
|
|
39
103
|
isAccountInstance,
|
|
40
104
|
isInitializationConfig,
|
|
41
105
|
isMnemonicInitializationConfig,
|
|
42
106
|
isPhraseInitializationConfig,
|
|
43
|
-
isPrivateKeyInitializationConfig
|
|
107
|
+
isPrivateKeyInitializationConfig,
|
|
108
|
+
isXyoAddress,
|
|
109
|
+
prefixForAlgorithm,
|
|
110
|
+
registerVerifier,
|
|
111
|
+
stripAddressPrefix,
|
|
112
|
+
verifySignature
|
|
44
113
|
};
|
|
45
114
|
//# 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;
|
|
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 {\n AddressZod, asAddress, isAddress, toUint8Array,\n} from '@xylabs/sdk-js'\nimport type * as z from 'zod/mini'\n\nimport { stripAddressPrefix } from './Algorithm.ts'\n\nexport const XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/\n\nexport const XyoAddressZod = AddressZod\n\nexport type XyoAddress = z.infer<typeof XyoAddressZod>\n\nexport function isXyoAddress(value: unknown): value is XyoAddress {\n return isAddress(value)\n}\n\nexport function asXyoAddress(value: unknown): XyoAddress | undefined {\n return asAddress(value)\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,MAA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SAAS,aAAa,OAAqC;AAChE,SAAO,UAAU,KAAK;AACxB;AAEO,SAAS,aAAa,OAAwC;AACnE,SAAO,UAAU,KAAK;AACxB;AAEO,SAAS,iBAAiB,SAAkC;AACjE,SAAO,aAAa,mBAAmB,OAAO,GAAG,EAAE,EAAE;AACvD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/node/Account.d.ts
CHANGED
|
@@ -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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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,12 @@
|
|
|
1
|
+
import type * as z from 'zod/mini';
|
|
2
|
+
export declare const XyoAddressRegEx: RegExp;
|
|
3
|
+
export declare const XyoAddressZod: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniTransform<Lowercase<string> & {
|
|
4
|
+
readonly __hex: true;
|
|
5
|
+
} & {
|
|
6
|
+
readonly __address: true;
|
|
7
|
+
}, string>>;
|
|
8
|
+
export type XyoAddress = z.infer<typeof XyoAddressZod>;
|
|
9
|
+
export declare function isXyoAddress(value: unknown): value is XyoAddress;
|
|
10
|
+
export declare function asXyoAddress(value: unknown): XyoAddress | undefined;
|
|
11
|
+
export declare function addressTo20Bytes(address: string): ArrayBufferLike;
|
|
12
|
+
//# sourceMappingURL=XyoAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XyoAddress.d.ts","sourceRoot":"","sources":["../../src/XyoAddress.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,CAAC,MAAM,UAAU,CAAA;AAIlC,eAAO,MAAM,eAAe,QAA4B,CAAA;AAExD,eAAO,MAAM,aAAa;;;;WAAa,CAAA;AAEvC,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AAEtD,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAEnE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAEjE"}
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/index.d.ts.map
CHANGED
|
@@ -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"}
|
package/dist/node/index.mjs
CHANGED
|
@@ -26,20 +26,89 @@ 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 {
|
|
75
|
+
AddressZod,
|
|
76
|
+
asAddress,
|
|
77
|
+
isAddress,
|
|
78
|
+
toUint8Array
|
|
79
|
+
} from "@xylabs/sdk-js";
|
|
80
|
+
var XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/;
|
|
81
|
+
var XyoAddressZod = AddressZod;
|
|
82
|
+
function isXyoAddress(value) {
|
|
83
|
+
return isAddress(value);
|
|
84
|
+
}
|
|
85
|
+
function asXyoAddress(value) {
|
|
86
|
+
return asAddress(value);
|
|
87
|
+
}
|
|
88
|
+
function addressTo20Bytes(address) {
|
|
89
|
+
return toUint8Array(stripAddressPrefix(address), 20).buffer;
|
|
90
|
+
}
|
|
34
91
|
export {
|
|
92
|
+
AccountAlgorithmPrefix,
|
|
35
93
|
JwtAlg,
|
|
36
94
|
JwtSchema,
|
|
37
95
|
JwtTyp,
|
|
96
|
+
XyoAddressRegEx,
|
|
97
|
+
XyoAddressZod,
|
|
98
|
+
addressTo20Bytes,
|
|
99
|
+
algorithmFromAddress,
|
|
100
|
+
asXyoAddress,
|
|
38
101
|
ethMessagePrefix,
|
|
102
|
+
getVerifier,
|
|
39
103
|
isAccountInstance,
|
|
40
104
|
isInitializationConfig,
|
|
41
105
|
isMnemonicInitializationConfig,
|
|
42
106
|
isPhraseInitializationConfig,
|
|
43
|
-
isPrivateKeyInitializationConfig
|
|
107
|
+
isPrivateKeyInitializationConfig,
|
|
108
|
+
isXyoAddress,
|
|
109
|
+
prefixForAlgorithm,
|
|
110
|
+
registerVerifier,
|
|
111
|
+
stripAddressPrefix,
|
|
112
|
+
verifySignature
|
|
44
113
|
};
|
|
45
114
|
//# sourceMappingURL=index.mjs.map
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -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;
|
|
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 {\n AddressZod, asAddress, isAddress, toUint8Array,\n} from '@xylabs/sdk-js'\nimport type * as z from 'zod/mini'\n\nimport { stripAddressPrefix } from './Algorithm.ts'\n\nexport const XyoAddressRegEx = /^(?:qr1_)?[0-9a-f]{40}$/\n\nexport const XyoAddressZod = AddressZod\n\nexport type XyoAddress = z.infer<typeof XyoAddressZod>\n\nexport function isXyoAddress(value: unknown): value is XyoAddress {\n return isAddress(value)\n}\n\nexport function asXyoAddress(value: unknown): XyoAddress | undefined {\n return asAddress(value)\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,SAA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AM,yCAAyC,SAAS,wCAAwC;AAAA,EAC5G;AACA,SAAO,MAAM,GAAG,SAAS,MAAM,SAAS;AAC1C;;;ACtBA;AAAA,EACE;AAAA,EAAY;AAAA,EAAW;AAAA,EAAW;AAAA,OAC7B;AAKA,IAAM,kBAAkB;AAExB,IAAM,gBAAgB;AAItB,SAAS,aAAa,OAAqC;AAChE,SAAO,UAAU,KAAK;AACxB;AAEO,SAAS,aAAa,OAAwC;AACnE,SAAO,UAAU,KAAK;AACxB;AAEO,SAAS,iBAAiB,SAAkC;AACjE,SAAO,aAAa,mBAAmB,OAAO,GAAG,EAAE,EAAE;AACvD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/account-model",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.4",
|
|
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/
|
|
38
|
-
"@xyo-network/
|
|
37
|
+
"@xyo-network/key-model": "~6.0.4",
|
|
38
|
+
"@xyo-network/previous-hash-store-model": "~6.0.4"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@opentelemetry/api": "^1.9.1",
|