@thru/sdk 0.2.22

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 (73) hide show
  1. package/README.abi.md +112 -0
  2. package/README.md +342 -0
  3. package/dist/abi/index.cjs +946 -0
  4. package/dist/abi/index.cjs.map +1 -0
  5. package/dist/abi/index.d.cts +331 -0
  6. package/dist/abi/index.d.ts +331 -0
  7. package/dist/abi/index.js +892 -0
  8. package/dist/abi/index.js.map +1 -0
  9. package/dist/abi/wasm/bundler/abi_reflect_wasm.d.ts +65 -0
  10. package/dist/abi/wasm/bundler/abi_reflect_wasm.js +5 -0
  11. package/dist/abi/wasm/bundler/abi_reflect_wasm_bg.js +412 -0
  12. package/dist/abi/wasm/bundler/abi_reflect_wasm_bg.wasm +0 -0
  13. package/dist/abi/wasm/bundler/abi_reflect_wasm_bg.wasm.d.ts +24 -0
  14. package/dist/abi/wasm/bundler/package.json +17 -0
  15. package/dist/abi/wasm/node/abi_reflect_wasm.d.ts +65 -0
  16. package/dist/abi/wasm/node/abi_reflect_wasm.js +425 -0
  17. package/dist/abi/wasm/node/abi_reflect_wasm_bg.wasm +0 -0
  18. package/dist/abi/wasm/node/abi_reflect_wasm_bg.wasm.d.ts +24 -0
  19. package/dist/abi/wasm/node/package.json +11 -0
  20. package/dist/abi/wasm/web/abi_reflect_wasm.d.ts +114 -0
  21. package/dist/abi/wasm/web/abi_reflect_wasm.js +499 -0
  22. package/dist/abi/wasm/web/abi_reflect_wasm_bg.wasm +0 -0
  23. package/dist/abi/wasm/web/abi_reflect_wasm_bg.wasm.d.ts +24 -0
  24. package/dist/abi/wasm/web/package.json +15 -0
  25. package/dist/chunk-CVBQ4UPL.js +3614 -0
  26. package/dist/chunk-CVBQ4UPL.js.map +1 -0
  27. package/dist/chunk-NSBPE2FW.js +15 -0
  28. package/dist/chunk-NSBPE2FW.js.map +1 -0
  29. package/dist/chunk-RL3Q6FDE.js +105 -0
  30. package/dist/chunk-RL3Q6FDE.js.map +1 -0
  31. package/dist/chunk-UDIXYJXC.js +260 -0
  32. package/dist/chunk-UDIXYJXC.js.map +1 -0
  33. package/dist/chunk-YQDWOMNO.js +271 -0
  34. package/dist/chunk-YQDWOMNO.js.map +1 -0
  35. package/dist/client-Cfi7zRLm.d.cts +1247 -0
  36. package/dist/client-worIo0a3.d.ts +1247 -0
  37. package/dist/client.cjs +3791 -0
  38. package/dist/client.cjs.map +1 -0
  39. package/dist/client.d.cts +7 -0
  40. package/dist/client.d.ts +7 -0
  41. package/dist/client.js +7 -0
  42. package/dist/client.js.map +1 -0
  43. package/dist/crypto/index.cjs +170 -0
  44. package/dist/crypto/index.cjs.map +1 -0
  45. package/dist/crypto/index.d.cts +60 -0
  46. package/dist/crypto/index.d.ts +60 -0
  47. package/dist/crypto/index.js +5 -0
  48. package/dist/crypto/index.js.map +1 -0
  49. package/dist/helpers/index.cjs +270 -0
  50. package/dist/helpers/index.cjs.map +1 -0
  51. package/dist/helpers/index.d.cts +15 -0
  52. package/dist/helpers/index.d.ts +15 -0
  53. package/dist/helpers/index.js +4 -0
  54. package/dist/helpers/index.js.map +1 -0
  55. package/dist/metafile-cjs.json +1 -0
  56. package/dist/metafile-esm.json +1 -0
  57. package/dist/proto/index.cjs +433 -0
  58. package/dist/proto/index.cjs.map +1 -0
  59. package/dist/proto/index.d.cts +435 -0
  60. package/dist/proto/index.d.ts +435 -0
  61. package/dist/proto/index.js +4 -0
  62. package/dist/proto/index.js.map +1 -0
  63. package/dist/sdk.cjs +4137 -0
  64. package/dist/sdk.cjs.map +1 -0
  65. package/dist/sdk.d.cts +36 -0
  66. package/dist/sdk.d.ts +36 -0
  67. package/dist/sdk.js +7 -0
  68. package/dist/sdk.js.map +1 -0
  69. package/dist/streaming_service_pb-DvCdJiCr.d.cts +4877 -0
  70. package/dist/streaming_service_pb-DvCdJiCr.d.ts +4877 -0
  71. package/dist/webcrypto-LTajLAad.d.cts +3 -0
  72. package/dist/webcrypto-LTajLAad.d.ts +3 -0
  73. package/package.json +88 -0
@@ -0,0 +1,7 @@
1
+ export { ad as Thru, ae as ThruClientConfig, ay as createThruClient } from './client-Cfi7zRLm.cjs';
2
+ import '@connectrpc/connect';
3
+ import '@connectrpc/connect-web';
4
+ import './streaming_service_pb-DvCdJiCr.cjs';
5
+ import '@bufbuild/protobuf/codegenv2';
6
+ import '@bufbuild/protobuf/wkt';
7
+ import '@bufbuild/protobuf';
@@ -0,0 +1,7 @@
1
+ export { ad as Thru, ae as ThruClientConfig, ay as createThruClient } from './client-worIo0a3.js';
2
+ import '@connectrpc/connect';
3
+ import '@connectrpc/connect-web';
4
+ import './streaming_service_pb-DvCdJiCr.js';
5
+ import '@bufbuild/protobuf/codegenv2';
6
+ import '@bufbuild/protobuf/wkt';
7
+ import '@bufbuild/protobuf';
package/dist/client.js ADDED
@@ -0,0 +1,7 @@
1
+ export { createThruClient } from './chunk-CVBQ4UPL.js';
2
+ import './chunk-YQDWOMNO.js';
3
+ import './chunk-RL3Q6FDE.js';
4
+ import './chunk-UDIXYJXC.js';
5
+ import './chunk-NSBPE2FW.js';
6
+ //# sourceMappingURL=client.js.map
7
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"client.js"}
@@ -0,0 +1,170 @@
1
+ 'use strict';
2
+
3
+ var HDKey = require('micro-key-producer/slip10.js');
4
+ var bip39 = require('@scure/bip39');
5
+ var english_js = require('@scure/bip39/wordlists/english.js');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var HDKey__default = /*#__PURE__*/_interopDefault(HDKey);
10
+
11
+ // src/helpers/constants.ts
12
+ var BASE64_URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
13
+ var tempMap = new Int16Array(256).fill(-1);
14
+ for (let i = 0; i < BASE64_URL_ALPHABET.length; i++) {
15
+ tempMap[BASE64_URL_ALPHABET.charCodeAt(i)] = i;
16
+ }
17
+
18
+ // src/helpers/address.ts
19
+ function encodeAddress(bytes) {
20
+ if (bytes.length !== 32) {
21
+ throw new Error("Expected 32-byte address");
22
+ }
23
+ let checksum = 0;
24
+ let accumulator = 0;
25
+ let bitsCollected = 0;
26
+ const output = ["t", "a"];
27
+ for (let i = 0; i < 30; i++) {
28
+ const byte = bytes[i];
29
+ checksum += byte;
30
+ accumulator = (accumulator << 8 | byte) >>> 0;
31
+ bitsCollected += 8;
32
+ while (bitsCollected >= 6) {
33
+ const index = accumulator >> bitsCollected - 6 & 63;
34
+ output.push(BASE64_URL_ALPHABET[index]);
35
+ bitsCollected -= 6;
36
+ accumulator &= maskForBits(bitsCollected);
37
+ }
38
+ }
39
+ const secondLast = bytes[30];
40
+ checksum += secondLast;
41
+ accumulator = (accumulator << 8 | secondLast) >>> 0;
42
+ bitsCollected += 8;
43
+ const last = bytes[31];
44
+ checksum += last;
45
+ accumulator = (accumulator << 8 | last) >>> 0;
46
+ bitsCollected += 8;
47
+ accumulator = (accumulator << 8 | checksum & 255) >>> 0;
48
+ bitsCollected += 8;
49
+ while (bitsCollected >= 6) {
50
+ const index = accumulator >> bitsCollected - 6 & 63;
51
+ output.push(BASE64_URL_ALPHABET[index]);
52
+ bitsCollected -= 6;
53
+ accumulator &= maskForBits(bitsCollected);
54
+ }
55
+ return output.join("");
56
+ }
57
+ function maskForBits(bits) {
58
+ return bits === 0 ? 0 : (1 << bits) - 1;
59
+ }
60
+
61
+ // src/helpers/webcrypto.ts
62
+ function getWebCrypto() {
63
+ const cryptoObj = typeof globalThis !== "undefined" ? globalThis.crypto : void 0;
64
+ if (cryptoObj && typeof cryptoObj.getRandomValues === "function") {
65
+ return cryptoObj;
66
+ }
67
+ throw new Error("Web Crypto API is unavailable. Provide a polyfill exposing globalThis.crypto.");
68
+ }
69
+ var _ThruHDWallet = class _ThruHDWallet {
70
+ static ensureSeed(seed) {
71
+ if (seed.length !== 64) {
72
+ throw new Error("Seed must be 64 bytes");
73
+ }
74
+ }
75
+ static deriveKeyPair(seed, path) {
76
+ _ThruHDWallet.ensureSeed(seed);
77
+ const hdkey = HDKey__default.default.fromMasterSeed(seed);
78
+ const derived = hdkey.derive(path);
79
+ if (!derived.privateKey || !derived.publicKey) {
80
+ throw new Error("Failed to derive key pair");
81
+ }
82
+ const privateKey = derived.privateKey;
83
+ const publicKey = derived.publicKeyRaw;
84
+ const secretKey = new Uint8Array(privateKey.length + publicKey.length);
85
+ secretKey.set(privateKey, 0);
86
+ secretKey.set(publicKey, privateKey.length);
87
+ return {
88
+ publicKey,
89
+ privateKey,
90
+ secretKey
91
+ };
92
+ }
93
+ static async getAccount(seed, accountIndex = 0, change = 0) {
94
+ if (accountIndex < 0) {
95
+ throw new Error("Account index must be non-negative");
96
+ }
97
+ const path = `${_ThruHDWallet.THRU_DERIVATION_PATH}/${accountIndex}'/${change}'`;
98
+ const { publicKey, privateKey, secretKey } = _ThruHDWallet.deriveKeyPair(seed, path);
99
+ return {
100
+ address: encodeAddress(publicKey),
101
+ publicKey,
102
+ privateKey,
103
+ secretKey,
104
+ path
105
+ };
106
+ }
107
+ static async deriveAccounts(seed, count) {
108
+ const accounts = [];
109
+ for (let i = 0; i < count; i++) {
110
+ const account = await _ThruHDWallet.getAccount(seed, i);
111
+ accounts.push({
112
+ index: i,
113
+ address: account.address,
114
+ path: account.path,
115
+ publicKey: account.publicKey
116
+ });
117
+ }
118
+ return accounts;
119
+ }
120
+ static isValidPath(path) {
121
+ const pathRegex = /^m(\/\d+')+$/;
122
+ return pathRegex.test(path);
123
+ }
124
+ };
125
+ _ThruHDWallet.THRU_COIN_TYPE = 9999;
126
+ _ThruHDWallet.THRU_DERIVATION_PATH = `m/44'/${_ThruHDWallet.THRU_COIN_TYPE}'`;
127
+ var ThruHDWallet = _ThruHDWallet;
128
+ var MnemonicGenerator = class {
129
+ /**
130
+ * Generate a new 12-word mnemonic phrase
131
+ * @returns 12-word mnemonic string
132
+ */
133
+ static generate() {
134
+ return bip39.generateMnemonic(english_js.wordlist, 128);
135
+ }
136
+ /**
137
+ * Validate a mnemonic phrase
138
+ * @param phrase - Mnemonic phrase to validate
139
+ * @returns true if valid, false otherwise
140
+ */
141
+ static validate(phrase) {
142
+ return bip39.validateMnemonic(phrase, english_js.wordlist);
143
+ }
144
+ /**
145
+ * Convert mnemonic phrase to seed bytes
146
+ * @param phrase - Valid mnemonic phrase
147
+ * @param passphrase - Optional passphrase for additional security
148
+ * @returns Seed as Uint8Array (64 bytes)
149
+ */
150
+ static toSeed(phrase, passphrase = "") {
151
+ if (!this.validate(phrase)) {
152
+ throw new Error("Invalid mnemonic phrase");
153
+ }
154
+ return bip39.mnemonicToSeedSync(phrase, passphrase);
155
+ }
156
+ /**
157
+ * Get the number of words in a mnemonic
158
+ * @param phrase - Mnemonic phrase
159
+ * @returns Number of words
160
+ */
161
+ static getWordCount(phrase) {
162
+ return phrase.trim().split(/\s+/).length;
163
+ }
164
+ };
165
+
166
+ exports.MnemonicGenerator = MnemonicGenerator;
167
+ exports.ThruHDWallet = ThruHDWallet;
168
+ exports.getWebCrypto = getWebCrypto;
169
+ //# sourceMappingURL=index.cjs.map
170
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/constants.ts","../../src/helpers/address.ts","../../src/helpers/webcrypto.ts","../../src/crypto/hdwallet.ts","../../src/crypto/mnemonic.ts"],"names":["HDKey","generateMnemonic","wordlist","validateMnemonic","mnemonicToSeedSync"],"mappings":";;;;;;;;;;;AAAO,IAAM,mBAAA,GAAsB,kEAAA;AAEnC,IAAM,UAAU,IAAI,UAAA,CAAW,GAAG,CAAA,CAAE,KAAK,EAAE,CAAA;AAC3C,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,mBAAA,CAAoB,QAAQ,CAAA,EAAA,EAAK;AACjD,EAAA,OAAA,CAAQ,mBAAA,CAAoB,UAAA,CAAW,CAAC,CAAC,CAAA,GAA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AAA;AAAA;AAAA;AAAA,EAOA,OAAO,aAAa,MAAA,EAAwB;AAC1C,IAAA,OAAO,MAAA,CAAO,IAAA,EAAK,CAAE,KAAA,CAAM,KAAK,CAAA,CAAE,MAAA;AAAA,EACpC;AACF","file":"index.cjs","sourcesContent":["export const BASE64_URL_ALPHABET = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\";\n\nconst tempMap = new Int16Array(256).fill(-1);\nfor (let i = 0; i < BASE64_URL_ALPHABET.length; i++) {\n tempMap[BASE64_URL_ALPHABET.charCodeAt(i)] = i;\n}\nexport const BASE64_URL_MAP = tempMap\n\n","import { BASE64_URL_ALPHABET, BASE64_URL_MAP } from \"./constants\";\n\nexport function encodeAddress(bytes: Uint8Array): string {\n if (bytes.length !== 32) {\n throw new Error('Expected 32-byte address');\n }\n\n let checksum = 0;\n let accumulator = 0;\n let bitsCollected = 0;\n const output: string[] = ['t', 'a'];\n\n for (let i = 0; i < 30; i++) {\n const byte = bytes[i];\n checksum += byte;\n accumulator = ((accumulator << 8) | byte) >>> 0;\n bitsCollected += 8;\n while (bitsCollected >= 6) {\n const index = (accumulator >> (bitsCollected - 6)) & 0x3f;\n output.push(BASE64_URL_ALPHABET[index]);\n bitsCollected -= 6;\n accumulator &= maskForBits(bitsCollected);\n }\n }\n\n const secondLast = bytes[30];\n checksum += secondLast;\n accumulator = ((accumulator << 8) | secondLast) >>> 0;\n bitsCollected += 8;\n\n const last = bytes[31];\n checksum += last;\n accumulator = ((accumulator << 8) | last) >>> 0;\n bitsCollected += 8;\n\n accumulator = ((accumulator << 8) | (checksum & 0xff)) >>> 0;\n bitsCollected += 8;\n\n while (bitsCollected >= 6) {\n const index = (accumulator >> (bitsCollected - 6)) & 0x3f;\n output.push(BASE64_URL_ALPHABET[index]);\n bitsCollected -= 6;\n accumulator &= maskForBits(bitsCollected);\n }\n\n return output.join('');\n}\n\nexport function decodeAddress(value: string): Uint8Array {\n if (value.length !== 46) {\n throw new Error('Invalid address length');\n }\n if (!value.startsWith('ta')) {\n throw new Error('Address must start with \"ta\"');\n }\n\n const output = new Uint8Array(32);\n let checksum = 0;\n let inIdx = 2;\n let remaining = 40;\n let outIdx = 0;\n\n while (remaining >= 4) {\n const a = BASE64_URL_MAP[value.charCodeAt(inIdx)];\n const b = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];\n const c = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];\n const d = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];\n if (a < 0 || b < 0 || c < 0 || d < 0) {\n throw new Error('Invalid address encoding');\n }\n const triple = (a << 18) | (b << 12) | (c << 6) | d;\n const byte1 = (triple >> 16) & 0xff;\n const byte2 = (triple >> 8) & 0xff;\n const byte3 = triple & 0xff;\n checksum += byte1;\n checksum += byte2;\n checksum += byte3;\n output[outIdx++] = byte1;\n output[outIdx++] = byte2;\n output[outIdx++] = byte3;\n inIdx += 4;\n remaining -= 4;\n }\n\n const a = BASE64_URL_MAP[value.charCodeAt(inIdx)];\n const b = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];\n const c = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];\n const d = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];\n if (a < 0 || b < 0 || c < 0 || d < 0) {\n throw new Error('Invalid address encoding');\n }\n const triple = (a << 18) | (b << 12) | (c << 6) | d;\n const byte1 = (triple >> 16) & 0xff;\n const byte2 = (triple >> 8) & 0xff;\n const incomingChecksum = triple & 0xff;\n\n checksum += byte1;\n checksum += byte2;\n output[outIdx++] = byte1;\n output[outIdx++] = byte2;\n\n checksum &= 0xff;\n if (checksum !== incomingChecksum) {\n throw new Error('Address checksum mismatch');\n }\n\n return output;\n}\n\nfunction maskForBits(bits: number): number {\n return bits === 0 ? 0 : (1 << bits) - 1;\n}\n","export function getWebCrypto(): Crypto {\n const cryptoObj = typeof globalThis !== 'undefined' ? (globalThis as { crypto?: Crypto }).crypto : undefined;\n\n if (cryptoObj && typeof cryptoObj.getRandomValues === 'function') {\n return cryptoObj;\n }\n\n throw new Error('Web Crypto API is unavailable. Provide a polyfill exposing globalThis.crypto.');\n}\n","import HDKey from 'micro-key-producer/slip10.js';\nimport { encodeAddress } from '@thru/sdk/helpers';\n\n/**\n * HD Wallet helpers for Thru (BIP44 coin type 9999).\n * Uses SLIP-0010 for Ed25519 key derivation via micro-key-producer.\n * Returns raw key material along with encoded addresses.\n */\nexport class ThruHDWallet {\n static readonly THRU_COIN_TYPE = 9999;\n static readonly THRU_DERIVATION_PATH = `m/44'/${ThruHDWallet.THRU_COIN_TYPE}'`;\n\n private static ensureSeed(seed: Uint8Array): void {\n if (seed.length !== 64) {\n throw new Error('Seed must be 64 bytes');\n }\n }\n\n private static deriveKeyPair(seed: Uint8Array, path: string) {\n ThruHDWallet.ensureSeed(seed);\n const hdkey = HDKey.fromMasterSeed(seed);\n const derived = hdkey.derive(path);\n\n if (!derived.privateKey || !derived.publicKey) {\n throw new Error('Failed to derive key pair');\n }\n\n const privateKey = derived.privateKey;\n const publicKey = derived.publicKeyRaw;\n const secretKey = new Uint8Array(privateKey.length + publicKey.length);\n secretKey.set(privateKey, 0);\n secretKey.set(publicKey, privateKey.length);\n\n return {\n publicKey,\n privateKey,\n secretKey,\n };\n }\n\n static async getAccount(\n seed: Uint8Array,\n accountIndex: number = 0,\n change: number = 0\n ): Promise<{\n address: string;\n publicKey: Uint8Array;\n privateKey: Uint8Array;\n secretKey: Uint8Array;\n path: string;\n }> {\n if (accountIndex < 0) {\n throw new Error('Account index must be non-negative');\n }\n\n const path = `${ThruHDWallet.THRU_DERIVATION_PATH}/${accountIndex}'/${change}'`;\n const { publicKey, privateKey, secretKey } = ThruHDWallet.deriveKeyPair(seed, path);\n\n return {\n address: encodeAddress(publicKey),\n publicKey,\n privateKey,\n secretKey,\n path,\n };\n }\n\n static async deriveAccounts(\n seed: Uint8Array,\n count: number\n ): Promise<Array<{\n index: number;\n address: string;\n path: string;\n publicKey: Uint8Array;\n }>> {\n const accounts = [];\n for (let i = 0; i < count; i++) {\n const account = await ThruHDWallet.getAccount(seed, i);\n accounts.push({\n index: i,\n address: account.address,\n path: account.path,\n publicKey: account.publicKey,\n });\n }\n return accounts;\n }\n\n static isValidPath(path: string): boolean {\n const pathRegex = /^m(\\/\\d+')+$/;\n return pathRegex.test(path);\n }\n}\n","import { generateMnemonic, validateMnemonic, mnemonicToSeedSync } from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english.js';\n\n/**\n * Handles BIP39 mnemonic phrase generation and validation.\n * Uses @scure/bip39 for React Native compatibility (no Buffer dependency).\n */\nexport class MnemonicGenerator {\n /**\n * Generate a new 12-word mnemonic phrase\n * @returns 12-word mnemonic string\n */\n static generate(): string {\n // 128 bits of entropy = 12 words\n return generateMnemonic(wordlist, 128);\n }\n\n /**\n * Validate a mnemonic phrase\n * @param phrase - Mnemonic phrase to validate\n * @returns true if valid, false otherwise\n */\n static validate(phrase: string): boolean {\n return validateMnemonic(phrase, wordlist);\n }\n\n /**\n * Convert mnemonic phrase to seed bytes\n * @param phrase - Valid mnemonic phrase\n * @param passphrase - Optional passphrase for additional security\n * @returns Seed as Uint8Array (64 bytes)\n */\n static toSeed(phrase: string, passphrase: string = ''): Uint8Array {\n if (!this.validate(phrase)) {\n throw new Error('Invalid mnemonic phrase');\n }\n // @scure/bip39 returns Uint8Array directly (no Buffer)\n return mnemonicToSeedSync(phrase, passphrase);\n }\n\n /**\n * Get the number of words in a mnemonic\n * @param phrase - Mnemonic phrase\n * @returns Number of words\n */\n static getWordCount(phrase: string): number {\n return phrase.trim().split(/\\s+/).length;\n }\n}\n"]}
@@ -0,0 +1,60 @@
1
+ export { g as getWebCrypto } from '../webcrypto-LTajLAad.cjs';
2
+
3
+ /**
4
+ * HD Wallet helpers for Thru (BIP44 coin type 9999).
5
+ * Uses SLIP-0010 for Ed25519 key derivation via micro-key-producer.
6
+ * Returns raw key material along with encoded addresses.
7
+ */
8
+ declare class ThruHDWallet {
9
+ static readonly THRU_COIN_TYPE = 9999;
10
+ static readonly THRU_DERIVATION_PATH: string;
11
+ private static ensureSeed;
12
+ private static deriveKeyPair;
13
+ static getAccount(seed: Uint8Array, accountIndex?: number, change?: number): Promise<{
14
+ address: string;
15
+ publicKey: Uint8Array;
16
+ privateKey: Uint8Array;
17
+ secretKey: Uint8Array;
18
+ path: string;
19
+ }>;
20
+ static deriveAccounts(seed: Uint8Array, count: number): Promise<Array<{
21
+ index: number;
22
+ address: string;
23
+ path: string;
24
+ publicKey: Uint8Array;
25
+ }>>;
26
+ static isValidPath(path: string): boolean;
27
+ }
28
+
29
+ /**
30
+ * Handles BIP39 mnemonic phrase generation and validation.
31
+ * Uses @scure/bip39 for React Native compatibility (no Buffer dependency).
32
+ */
33
+ declare class MnemonicGenerator {
34
+ /**
35
+ * Generate a new 12-word mnemonic phrase
36
+ * @returns 12-word mnemonic string
37
+ */
38
+ static generate(): string;
39
+ /**
40
+ * Validate a mnemonic phrase
41
+ * @param phrase - Mnemonic phrase to validate
42
+ * @returns true if valid, false otherwise
43
+ */
44
+ static validate(phrase: string): boolean;
45
+ /**
46
+ * Convert mnemonic phrase to seed bytes
47
+ * @param phrase - Valid mnemonic phrase
48
+ * @param passphrase - Optional passphrase for additional security
49
+ * @returns Seed as Uint8Array (64 bytes)
50
+ */
51
+ static toSeed(phrase: string, passphrase?: string): Uint8Array;
52
+ /**
53
+ * Get the number of words in a mnemonic
54
+ * @param phrase - Mnemonic phrase
55
+ * @returns Number of words
56
+ */
57
+ static getWordCount(phrase: string): number;
58
+ }
59
+
60
+ export { MnemonicGenerator, ThruHDWallet };
@@ -0,0 +1,60 @@
1
+ export { g as getWebCrypto } from '../webcrypto-LTajLAad.js';
2
+
3
+ /**
4
+ * HD Wallet helpers for Thru (BIP44 coin type 9999).
5
+ * Uses SLIP-0010 for Ed25519 key derivation via micro-key-producer.
6
+ * Returns raw key material along with encoded addresses.
7
+ */
8
+ declare class ThruHDWallet {
9
+ static readonly THRU_COIN_TYPE = 9999;
10
+ static readonly THRU_DERIVATION_PATH: string;
11
+ private static ensureSeed;
12
+ private static deriveKeyPair;
13
+ static getAccount(seed: Uint8Array, accountIndex?: number, change?: number): Promise<{
14
+ address: string;
15
+ publicKey: Uint8Array;
16
+ privateKey: Uint8Array;
17
+ secretKey: Uint8Array;
18
+ path: string;
19
+ }>;
20
+ static deriveAccounts(seed: Uint8Array, count: number): Promise<Array<{
21
+ index: number;
22
+ address: string;
23
+ path: string;
24
+ publicKey: Uint8Array;
25
+ }>>;
26
+ static isValidPath(path: string): boolean;
27
+ }
28
+
29
+ /**
30
+ * Handles BIP39 mnemonic phrase generation and validation.
31
+ * Uses @scure/bip39 for React Native compatibility (no Buffer dependency).
32
+ */
33
+ declare class MnemonicGenerator {
34
+ /**
35
+ * Generate a new 12-word mnemonic phrase
36
+ * @returns 12-word mnemonic string
37
+ */
38
+ static generate(): string;
39
+ /**
40
+ * Validate a mnemonic phrase
41
+ * @param phrase - Mnemonic phrase to validate
42
+ * @returns true if valid, false otherwise
43
+ */
44
+ static validate(phrase: string): boolean;
45
+ /**
46
+ * Convert mnemonic phrase to seed bytes
47
+ * @param phrase - Valid mnemonic phrase
48
+ * @param passphrase - Optional passphrase for additional security
49
+ * @returns Seed as Uint8Array (64 bytes)
50
+ */
51
+ static toSeed(phrase: string, passphrase?: string): Uint8Array;
52
+ /**
53
+ * Get the number of words in a mnemonic
54
+ * @param phrase - Mnemonic phrase
55
+ * @returns Number of words
56
+ */
57
+ static getWordCount(phrase: string): number;
58
+ }
59
+
60
+ export { MnemonicGenerator, ThruHDWallet };
@@ -0,0 +1,5 @@
1
+ export { MnemonicGenerator, ThruHDWallet } from '../chunk-RL3Q6FDE.js';
2
+ export { getWebCrypto } from '../chunk-UDIXYJXC.js';
3
+ import '../chunk-NSBPE2FW.js';
4
+ //# sourceMappingURL=index.js.map
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,270 @@
1
+ 'use strict';
2
+
3
+ // src/helpers/constants.ts
4
+ var BASE64_URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
5
+ var tempMap = new Int16Array(256).fill(-1);
6
+ for (let i = 0; i < BASE64_URL_ALPHABET.length; i++) {
7
+ tempMap[BASE64_URL_ALPHABET.charCodeAt(i)] = i;
8
+ }
9
+ var BASE64_URL_MAP = tempMap;
10
+
11
+ // src/helpers/address.ts
12
+ function encodeAddress(bytes) {
13
+ if (bytes.length !== 32) {
14
+ throw new Error("Expected 32-byte address");
15
+ }
16
+ let checksum = 0;
17
+ let accumulator = 0;
18
+ let bitsCollected = 0;
19
+ const output = ["t", "a"];
20
+ for (let i = 0; i < 30; i++) {
21
+ const byte = bytes[i];
22
+ checksum += byte;
23
+ accumulator = (accumulator << 8 | byte) >>> 0;
24
+ bitsCollected += 8;
25
+ while (bitsCollected >= 6) {
26
+ const index = accumulator >> bitsCollected - 6 & 63;
27
+ output.push(BASE64_URL_ALPHABET[index]);
28
+ bitsCollected -= 6;
29
+ accumulator &= maskForBits(bitsCollected);
30
+ }
31
+ }
32
+ const secondLast = bytes[30];
33
+ checksum += secondLast;
34
+ accumulator = (accumulator << 8 | secondLast) >>> 0;
35
+ bitsCollected += 8;
36
+ const last = bytes[31];
37
+ checksum += last;
38
+ accumulator = (accumulator << 8 | last) >>> 0;
39
+ bitsCollected += 8;
40
+ accumulator = (accumulator << 8 | checksum & 255) >>> 0;
41
+ bitsCollected += 8;
42
+ while (bitsCollected >= 6) {
43
+ const index = accumulator >> bitsCollected - 6 & 63;
44
+ output.push(BASE64_URL_ALPHABET[index]);
45
+ bitsCollected -= 6;
46
+ accumulator &= maskForBits(bitsCollected);
47
+ }
48
+ return output.join("");
49
+ }
50
+ function decodeAddress(value) {
51
+ if (value.length !== 46) {
52
+ throw new Error("Invalid address length");
53
+ }
54
+ if (!value.startsWith("ta")) {
55
+ throw new Error('Address must start with "ta"');
56
+ }
57
+ const output = new Uint8Array(32);
58
+ let checksum = 0;
59
+ let inIdx = 2;
60
+ let remaining = 40;
61
+ let outIdx = 0;
62
+ while (remaining >= 4) {
63
+ const a2 = BASE64_URL_MAP[value.charCodeAt(inIdx)];
64
+ const b2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];
65
+ const c2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];
66
+ const d2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];
67
+ if (a2 < 0 || b2 < 0 || c2 < 0 || d2 < 0) {
68
+ throw new Error("Invalid address encoding");
69
+ }
70
+ const triple2 = a2 << 18 | b2 << 12 | c2 << 6 | d2;
71
+ const byte12 = triple2 >> 16 & 255;
72
+ const byte22 = triple2 >> 8 & 255;
73
+ const byte3 = triple2 & 255;
74
+ checksum += byte12;
75
+ checksum += byte22;
76
+ checksum += byte3;
77
+ output[outIdx++] = byte12;
78
+ output[outIdx++] = byte22;
79
+ output[outIdx++] = byte3;
80
+ inIdx += 4;
81
+ remaining -= 4;
82
+ }
83
+ const a = BASE64_URL_MAP[value.charCodeAt(inIdx)];
84
+ const b = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];
85
+ const c = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];
86
+ const d = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];
87
+ if (a < 0 || b < 0 || c < 0 || d < 0) {
88
+ throw new Error("Invalid address encoding");
89
+ }
90
+ const triple = a << 18 | b << 12 | c << 6 | d;
91
+ const byte1 = triple >> 16 & 255;
92
+ const byte2 = triple >> 8 & 255;
93
+ const incomingChecksum = triple & 255;
94
+ checksum += byte1;
95
+ checksum += byte2;
96
+ output[outIdx++] = byte1;
97
+ output[outIdx++] = byte2;
98
+ checksum &= 255;
99
+ if (checksum !== incomingChecksum) {
100
+ throw new Error("Address checksum mismatch");
101
+ }
102
+ return output;
103
+ }
104
+ function maskForBits(bits) {
105
+ return bits === 0 ? 0 : (1 << bits) - 1;
106
+ }
107
+
108
+ // src/helpers/encoding.ts
109
+ function decodeBase64(value) {
110
+ if (value.length === 0) {
111
+ return new Uint8Array();
112
+ }
113
+ const atobFn = globalThis.atob;
114
+ if (!atobFn) {
115
+ throw new Error("Base64 decoding requires globalThis.atob support");
116
+ }
117
+ const binary = atobFn(value);
118
+ const bytes = new Uint8Array(binary.length);
119
+ for (let i = 0; i < binary.length; i++) {
120
+ bytes[i] = binary.charCodeAt(i);
121
+ }
122
+ return bytes;
123
+ }
124
+ function hexToBytes(value) {
125
+ const normalized = value.startsWith("0x") ? value.slice(2) : value;
126
+ if (normalized.length % 2 !== 0) {
127
+ throw new Error("Hex string must contain an even number of characters");
128
+ }
129
+ const bytes = new Uint8Array(normalized.length / 2);
130
+ for (let i = 0; i < normalized.length; i += 2) {
131
+ const byte = parseInt(normalized.slice(i, i + 2), 16);
132
+ if (Number.isNaN(byte)) {
133
+ throw new Error("Hex string contains invalid characters");
134
+ }
135
+ bytes[i / 2] = byte;
136
+ }
137
+ return bytes;
138
+ }
139
+ function isHexString(value) {
140
+ const normalized = value.startsWith("0x") ? value.slice(2) : value;
141
+ return normalized.length % 2 === 0 && normalized.length > 0 && /^[0-9a-fA-F]+$/.test(normalized);
142
+ }
143
+
144
+ // src/helpers/utils.ts
145
+ function ensureBytes(value, field) {
146
+ if (value instanceof Uint8Array) {
147
+ if (value.length === 0) {
148
+ throw new Error(`${field} cannot be empty`);
149
+ }
150
+ return value;
151
+ }
152
+ if (typeof value === "string") {
153
+ if (value.length === 0) {
154
+ throw new Error(`${field} cannot be empty`);
155
+ }
156
+ return decodeBase64(value);
157
+ }
158
+ throw new Error(`${field} is required`);
159
+ }
160
+ function maskForBits2(bits) {
161
+ return bits === 0 ? 0 : (1 << bits) - 1;
162
+ }
163
+
164
+ // src/helpers/signature.ts
165
+ function encodeSignature(bytes) {
166
+ if (bytes.length !== 64) {
167
+ throw new Error("Expected 64-byte signature");
168
+ }
169
+ let checksum = 0;
170
+ let accumulator = 0;
171
+ let bitsCollected = 0;
172
+ const output = ["t", "s"];
173
+ for (let i = 0; i < 63; i++) {
174
+ const byte = bytes[i];
175
+ checksum += byte;
176
+ accumulator = (accumulator << 8 | byte) >>> 0;
177
+ bitsCollected += 8;
178
+ while (bitsCollected >= 6) {
179
+ const index = accumulator >> bitsCollected - 6 & 63;
180
+ output.push(BASE64_URL_ALPHABET[index]);
181
+ bitsCollected -= 6;
182
+ accumulator &= maskForBits2(bitsCollected);
183
+ }
184
+ }
185
+ const lastByte = bytes[63];
186
+ checksum += lastByte;
187
+ accumulator = (accumulator << 8 | lastByte) >>> 0;
188
+ bitsCollected += 8;
189
+ accumulator = (accumulator << 16 | checksum & 65535) >>> 0;
190
+ bitsCollected += 16;
191
+ while (bitsCollected >= 6) {
192
+ const index = accumulator >> bitsCollected - 6 & 63;
193
+ output.push(BASE64_URL_ALPHABET[index]);
194
+ bitsCollected -= 6;
195
+ accumulator &= maskForBits2(bitsCollected);
196
+ }
197
+ return output.join("");
198
+ }
199
+ function decodeSignature(value) {
200
+ if (value.length !== 90) {
201
+ throw new Error("Invalid signature length");
202
+ }
203
+ if (!value.startsWith("ts")) {
204
+ throw new Error('Signature must start with "ts"');
205
+ }
206
+ const output = new Uint8Array(64);
207
+ let checksum = 0;
208
+ let inIdx = 2;
209
+ let remaining = 84;
210
+ let outIdx = 0;
211
+ while (remaining > 0) {
212
+ const a2 = BASE64_URL_MAP[value.charCodeAt(inIdx)];
213
+ const b2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];
214
+ const c2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];
215
+ const d2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];
216
+ if (a2 < 0 || b2 < 0 || c2 < 0 || d2 < 0) {
217
+ throw new Error("Invalid signature encoding");
218
+ }
219
+ const triple2 = a2 << 18 | b2 << 12 | c2 << 6 | d2;
220
+ const byte1 = triple2 >> 16 & 255;
221
+ const byte2 = triple2 >> 8 & 255;
222
+ const byte3 = triple2 & 255;
223
+ checksum += byte1;
224
+ checksum += byte2;
225
+ checksum += byte3;
226
+ output[outIdx++] = byte1;
227
+ output[outIdx++] = byte2;
228
+ output[outIdx++] = byte3;
229
+ inIdx += 4;
230
+ remaining -= 4;
231
+ }
232
+ const a = BASE64_URL_MAP[value.charCodeAt(inIdx)];
233
+ const b = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];
234
+ const c = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];
235
+ const d = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];
236
+ if (a < 0 || b < 0 || c < 0 || d < 0) {
237
+ throw new Error("Invalid signature encoding");
238
+ }
239
+ const triple = a << 18 | b << 12 | c << 6 | d;
240
+ const finalByte = triple >> 16 & 255;
241
+ checksum += finalByte;
242
+ output[outIdx] = finalByte;
243
+ const incomingChecksum = triple & 65535;
244
+ checksum &= 65535;
245
+ if (checksum !== incomingChecksum) {
246
+ throw new Error("Signature checksum mismatch");
247
+ }
248
+ return output;
249
+ }
250
+
251
+ // src/helpers/webcrypto.ts
252
+ function getWebCrypto() {
253
+ const cryptoObj = typeof globalThis !== "undefined" ? globalThis.crypto : void 0;
254
+ if (cryptoObj && typeof cryptoObj.getRandomValues === "function") {
255
+ return cryptoObj;
256
+ }
257
+ throw new Error("Web Crypto API is unavailable. Provide a polyfill exposing globalThis.crypto.");
258
+ }
259
+
260
+ exports.decodeAddress = decodeAddress;
261
+ exports.decodeBase64 = decodeBase64;
262
+ exports.decodeSignature = decodeSignature;
263
+ exports.encodeAddress = encodeAddress;
264
+ exports.encodeSignature = encodeSignature;
265
+ exports.ensureBytes = ensureBytes;
266
+ exports.getWebCrypto = getWebCrypto;
267
+ exports.hexToBytes = hexToBytes;
268
+ exports.isHexString = isHexString;
269
+ //# sourceMappingURL=index.cjs.map
270
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/constants.ts","../../src/helpers/address.ts","../../src/helpers/encoding.ts","../../src/helpers/utils.ts","../../src/helpers/signature.ts","../../src/helpers/webcrypto.ts"],"names":["a","b","c","d","triple","byte1","byte2","maskForBits"],"mappings":";;;AAAO,IAAM,mBAAA,GAAsB,kEAAA;AAEnC,IAAM,UAAU,IAAI,UAAA,CAAW,GAAG,CAAA,CAAE,KAAK,EAAE,CAAA;AAC3C,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,mBAAA,CAAoB,QAAQ,CAAA,EAAA,EAAK;AACjD,EAAA,OAAA,CAAQ,mBAAA,CAAoB,UAAA,CAAW,CAAC,CAAC,CAAA,GAAI,CAAA;AACjD;AACO,IAAM,cAAA,GAAiB,OAAA;;;ACJvB,SAAS,cAAc,KAAA,EAA2B;AACvD,EAAA,IAAI,KAAA,CAAM,WAAW,EAAA,EAAI;AACvB,IAAA,MAAM,IAAI,MAAM,0BAA0B,CAAA;AAAA,EAC5C;AAEA,EAAA,IAAI,QAAA,GAAW,CAAA;AACf,EAAA,IAAI,WAAA,GAAc,CAAA;AAClB,EAAA,IAAI,aAAA,GAAgB,CAAA;AACpB,EAAA,MAAM,MAAA,GAAmB,CAAC,GAAA,EAAK,GAAG,CAAA;AAElC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,EAAA,EAAI,CAAA,EAAA,EAAK;AAC3B,IAAA,MAAM,IAAA,GAAO,MAAM,CAAC,CAAA;AACpB,IAAA,QAAA,IAAY,IAAA;AACZ,IAAA,WAAA,GAAA,CAAgB,WAAA,IAAe,IAAK,IAAA,MAAU,CAAA;AAC9C,IAAA,aAAA,IAAiB,CAAA;AACjB,IAAA,OAAO,iBAAiB,CAAA,EAAG;AACzB,MAAA,MAAM,KAAA,GAAS,WAAA,IAAgB,aAAA,GAAgB,CAAA,GAAM,EAAA;AACrD,MAAA,MAAA,CAAO,IAAA,CAAK,mBAAA,CAAoB,KAAK,CAAC,CAAA;A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AM,CAAA,GAAI,SAAA;AAEjB,EAAA,MAAM,mBAAmB,MAAA,GAAS,KAAA;AAClC,EAAA,QAAA,IAAY,KAAA;AACZ,EAAA,IAAI,aAAa,gBAAA,EAAkB;AAC/B,IAAA,MAAM,IAAI,MAAM,6BAA6B,CAAA;AAAA,EACjD;AAEA,EAAA,OAAO,MAAA;AACX;;;ACjGO,SAAS,YAAA,GAAuB;AACrC,EAAA,MAAM,SAAA,GAAY,OAAO,UAAA,KAAe,WAAA,GAAe,WAAmC,MAAA,GAAS,MAAA;AAEnG,EAAA,IAAI,SAAA,IAAa,OAAO,SAAA,CAAU,eAAA,KAAoB,UAAA,EAAY;AAChE,IAAA,OAAO,SAAA;AAAA,EACT;AAEA,EAAA,MAAM,IAAI,MAAM,+EAA+E,CAAA;AACjG","file":"index.cjs","sourcesContent":["export const BASE64_URL_ALPHABET = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\";\n\nconst tempMap = new Int16Array(256).fill(-1);\nfor (let i = 0; i < BASE64_URL_ALPHABET.length; i++) {\n tempMap[BASE64_URL_ALPHABET.charCodeAt(i)] = i;\n}\nexport const BASE64_URL_MAP = tempMap\n\n","import { BASE64_URL_ALPHABET, BASE64_URL_MAP } from \"./constants\";\n\nexport function encodeAddress(bytes: Uint8Array): string {\n if (bytes.length !== 32) {\n throw new Error('Expected 32-byte address');\n }\n\n let checksum = 0;\n let accumulator = 0;\n let bitsCollected = 0;\n const output: string[] = ['t', 'a'];\n\n for (let i = 0; i < 30; i++) {\n const byte = bytes[i];\n checksum += byte;\n accumulator = ((accumulator << 8) | byte) >>> 0;\n bitsCollected += 8;\n while (bitsCollected >= 6) {\n const index = (accumulator >> (bitsCollected - 6)) & 0x3f;\n output.push(BASE64_URL_ALPHABET[index]);\n bitsCollected -= 6;\n accumulator &= maskForBits(bitsCollected);\n }\n }\n\n const secondLast = bytes[30];\n checksum += secondLast;\n accumulator = ((accumulator << 8) | secondLast) >>> 0;\n bitsCollected += 8;\n\n const last = bytes[31];\n checksum += last;\n accumulator = ((accumulator << 8) | last) >>> 0;\n bitsCollected += 8;\n\n accumulator = ((accumulator << 8) | (checksum & 0xff)) >>> 0;\n bitsCollected += 8;\n\n while (bitsCollected >= 6) {\n const index = (accumulator >> (bitsCollected - 6)) & 0x3f;\n output.push(BASE64_URL_ALPHABET[index]);\n bitsCollected -= 6;\n accumulator &= maskForBits(bitsCollected);\n }\n\n return output.join('');\n}\n\nexport function decodeAddress(value: string): Uint8Array {\n if (value.length !== 46) {\n throw new Error('Invalid address length');\n }\n if (!value.startsWith('ta')) {\n throw new Error('Address must start with \"ta\"');\n }\n\n const output = new Uint8Array(32);\n let checksum = 0;\n let inIdx = 2;\n let remaining = 40;\n let outIdx = 0;\n\n while (remaining >= 4) {\n const a = BASE64_URL_MAP[value.charCodeAt(inIdx)];\n const b = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];\n const c = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];\n const d = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];\n if (a < 0 || b < 0 || c < 0 || d < 0) {\n throw new Error('Invalid address encoding');\n }\n const triple = (a << 18) | (b << 12) | (c << 6) | d;\n const byte1 = (triple >> 16) & 0xff;\n const byte2 = (triple >> 8) & 0xff;\n const byte3 = triple & 0xff;\n checksum += byte1;\n checksum += byte2;\n checksum += byte3;\n output[outIdx++] = byte1;\n output[outIdx++] = byte2;\n output[outIdx++] = byte3;\n inIdx += 4;\n remaining -= 4;\n }\n\n const a = BASE64_URL_MAP[value.charCodeAt(inIdx)];\n const b = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];\n const c = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];\n const d = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];\n if (a < 0 || b < 0 || c < 0 || d < 0) {\n throw new Error('Invalid address encoding');\n }\n const triple = (a << 18) | (b << 12) | (c << 6) | d;\n const byte1 = (triple >> 16) & 0xff;\n const byte2 = (triple >> 8) & 0xff;\n const incomingChecksum = triple & 0xff;\n\n checksum += byte1;\n checksum += byte2;\n output[outIdx++] = byte1;\n output[outIdx++] = byte2;\n\n checksum &= 0xff;\n if (checksum !== incomingChecksum) {\n throw new Error('Address checksum mismatch');\n }\n\n return output;\n}\n\nfunction maskForBits(bits: number): number {\n return bits === 0 ? 0 : (1 << bits) - 1;\n}\n","export function decodeBase64(value: string): Uint8Array {\n if (value.length === 0) {\n return new Uint8Array();\n }\n const atobFn = globalThis.atob;\n if (!atobFn) {\n throw new Error('Base64 decoding requires globalThis.atob support');\n }\n const binary = atobFn(value);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\nexport function hexToBytes(value: string): Uint8Array {\n const normalized = value.startsWith('0x') ? value.slice(2) : value;\n if (normalized.length % 2 !== 0) {\n throw new Error('Hex string must contain an even number of characters');\n }\n const bytes = new Uint8Array(normalized.length / 2);\n for (let i = 0; i < normalized.length; i += 2) {\n const byte = parseInt(normalized.slice(i, i + 2), 16);\n if (Number.isNaN(byte)) {\n throw new Error('Hex string contains invalid characters');\n }\n bytes[i / 2] = byte;\n }\n return bytes;\n}\n\nexport function isHexString(value: string): boolean {\n const normalized = value.startsWith('0x') ? value.slice(2) : value;\n return normalized.length % 2 === 0 && normalized.length > 0 && /^[0-9a-fA-F]+$/.test(normalized);\n}\n","import { decodeBase64 } from \"./encoding\";\n\nexport function ensureBytes(value: Uint8Array | string | undefined, field: string): Uint8Array {\n if (value instanceof Uint8Array) {\n if (value.length === 0) {\n throw new Error(`${field} cannot be empty`);\n }\n return value;\n }\n if (typeof value === \"string\") {\n if (value.length === 0) {\n throw new Error(`${field} cannot be empty`);\n }\n return decodeBase64(value);\n }\n throw new Error(`${field} is required`);\n}\n\nexport function maskForBits(bits: number): number {\n return bits === 0 ? 0 : (1 << bits) - 1;\n}","import { BASE64_URL_ALPHABET, BASE64_URL_MAP } from \"./constants\";\nimport { maskForBits } from \"./utils\";\n\nexport function encodeSignature(bytes: Uint8Array): string {\n if (bytes.length !== 64) {\n throw new Error(\"Expected 64-byte signature\");\n }\n let checksum = 0;\n let accumulator = 0;\n let bitsCollected = 0;\n const output: string[] = [\"t\", \"s\"];\n\n for (let i = 0; i < 63; i++) {\n const byte = bytes[i];\n checksum += byte;\n accumulator = ((accumulator << 8) | byte) >>> 0;\n bitsCollected += 8;\n while (bitsCollected >= 6) {\n const index = (accumulator >> (bitsCollected - 6)) & 0x3f;\n output.push(BASE64_URL_ALPHABET[index]);\n bitsCollected -= 6;\n accumulator &= maskForBits(bitsCollected);\n }\n }\n\n const lastByte = bytes[63];\n checksum += lastByte;\n accumulator = ((accumulator << 8) | lastByte) >>> 0;\n bitsCollected += 8;\n accumulator = ((accumulator << 16) | (checksum & 0xffff)) >>> 0;\n bitsCollected += 16;\n\n while (bitsCollected >= 6) {\n const index = (accumulator >> (bitsCollected - 6)) & 0x3f;\n output.push(BASE64_URL_ALPHABET[index]);\n bitsCollected -= 6;\n accumulator &= maskForBits(bitsCollected);\n }\n\n return output.join(\"\");\n}\n\nexport function decodeSignature(value: string): Uint8Array {\n if (value.length !== 90) {\n throw new Error(\"Invalid signature length\");\n }\n if (!value.startsWith(\"ts\")) {\n throw new Error('Signature must start with \"ts\"');\n }\n\n const output = new Uint8Array(64);\n let checksum = 0;\n let inIdx = 2;\n let remaining = 84;\n let outIdx = 0;\n\n while (remaining > 0) {\n const a = BASE64_URL_MAP[value.charCodeAt(inIdx)];\n const b = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];\n const c = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];\n const d = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];\n if (a < 0 || b < 0 || c < 0 || d < 0) {\n throw new Error(\"Invalid signature encoding\");\n }\n const triple = (a << 18) | (b << 12) | (c << 6) | d;\n const byte1 = (triple >> 16) & 0xff;\n const byte2 = (triple >> 8) & 0xff;\n const byte3 = triple & 0xff;\n checksum += byte1;\n checksum += byte2;\n checksum += byte3;\n output[outIdx++] = byte1;\n output[outIdx++] = byte2;\n output[outIdx++] = byte3;\n inIdx += 4;\n remaining -= 4;\n }\n\n const a = BASE64_URL_MAP[value.charCodeAt(inIdx)];\n const b = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];\n const c = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];\n const d = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];\n if (a < 0 || b < 0 || c < 0 || d < 0) {\n throw new Error(\"Invalid signature encoding\");\n }\n const triple = (a << 18) | (b << 12) | (c << 6) | d;\n const finalByte = (triple >> 16) & 0xff;\n checksum += finalByte;\n output[outIdx] = finalByte;\n\n const incomingChecksum = triple & 0xffff;\n checksum &= 0xffff;\n if (checksum !== incomingChecksum) {\n throw new Error(\"Signature checksum mismatch\");\n }\n\n return output;\n}","export function getWebCrypto(): Crypto {\n const cryptoObj = typeof globalThis !== 'undefined' ? (globalThis as { crypto?: Crypto }).crypto : undefined;\n\n if (cryptoObj && typeof cryptoObj.getRandomValues === 'function') {\n return cryptoObj;\n }\n\n throw new Error('Web Crypto API is unavailable. Provide a polyfill exposing globalThis.crypto.');\n}\n"]}