@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.
- package/README.abi.md +112 -0
- package/README.md +342 -0
- package/dist/abi/index.cjs +946 -0
- package/dist/abi/index.cjs.map +1 -0
- package/dist/abi/index.d.cts +331 -0
- package/dist/abi/index.d.ts +331 -0
- package/dist/abi/index.js +892 -0
- package/dist/abi/index.js.map +1 -0
- package/dist/abi/wasm/bundler/abi_reflect_wasm.d.ts +65 -0
- package/dist/abi/wasm/bundler/abi_reflect_wasm.js +5 -0
- package/dist/abi/wasm/bundler/abi_reflect_wasm_bg.js +412 -0
- package/dist/abi/wasm/bundler/abi_reflect_wasm_bg.wasm +0 -0
- package/dist/abi/wasm/bundler/abi_reflect_wasm_bg.wasm.d.ts +24 -0
- package/dist/abi/wasm/bundler/package.json +17 -0
- package/dist/abi/wasm/node/abi_reflect_wasm.d.ts +65 -0
- package/dist/abi/wasm/node/abi_reflect_wasm.js +425 -0
- package/dist/abi/wasm/node/abi_reflect_wasm_bg.wasm +0 -0
- package/dist/abi/wasm/node/abi_reflect_wasm_bg.wasm.d.ts +24 -0
- package/dist/abi/wasm/node/package.json +11 -0
- package/dist/abi/wasm/web/abi_reflect_wasm.d.ts +114 -0
- package/dist/abi/wasm/web/abi_reflect_wasm.js +499 -0
- package/dist/abi/wasm/web/abi_reflect_wasm_bg.wasm +0 -0
- package/dist/abi/wasm/web/abi_reflect_wasm_bg.wasm.d.ts +24 -0
- package/dist/abi/wasm/web/package.json +15 -0
- package/dist/chunk-CVBQ4UPL.js +3614 -0
- package/dist/chunk-CVBQ4UPL.js.map +1 -0
- package/dist/chunk-NSBPE2FW.js +15 -0
- package/dist/chunk-NSBPE2FW.js.map +1 -0
- package/dist/chunk-RL3Q6FDE.js +105 -0
- package/dist/chunk-RL3Q6FDE.js.map +1 -0
- package/dist/chunk-UDIXYJXC.js +260 -0
- package/dist/chunk-UDIXYJXC.js.map +1 -0
- package/dist/chunk-YQDWOMNO.js +271 -0
- package/dist/chunk-YQDWOMNO.js.map +1 -0
- package/dist/client-Cfi7zRLm.d.cts +1247 -0
- package/dist/client-worIo0a3.d.ts +1247 -0
- package/dist/client.cjs +3791 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +7 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +7 -0
- package/dist/client.js.map +1 -0
- package/dist/crypto/index.cjs +170 -0
- package/dist/crypto/index.cjs.map +1 -0
- package/dist/crypto/index.d.cts +60 -0
- package/dist/crypto/index.d.ts +60 -0
- package/dist/crypto/index.js +5 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/helpers/index.cjs +270 -0
- package/dist/helpers/index.cjs.map +1 -0
- package/dist/helpers/index.d.cts +15 -0
- package/dist/helpers/index.d.ts +15 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/proto/index.cjs +433 -0
- package/dist/proto/index.cjs.map +1 -0
- package/dist/proto/index.d.cts +435 -0
- package/dist/proto/index.d.ts +435 -0
- package/dist/proto/index.js +4 -0
- package/dist/proto/index.js.map +1 -0
- package/dist/sdk.cjs +4137 -0
- package/dist/sdk.cjs.map +1 -0
- package/dist/sdk.d.cts +36 -0
- package/dist/sdk.d.ts +36 -0
- package/dist/sdk.js +7 -0
- package/dist/sdk.js.map +1 -0
- package/dist/streaming_service_pb-DvCdJiCr.d.cts +4877 -0
- package/dist/streaming_service_pb-DvCdJiCr.d.ts +4877 -0
- package/dist/webcrypto-LTajLAad.d.cts +3 -0
- package/dist/webcrypto-LTajLAad.d.ts +3 -0
- package/package.json +88 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { __export, __require };
|
|
14
|
+
//# sourceMappingURL=chunk-NSBPE2FW.js.map
|
|
15
|
+
//# sourceMappingURL=chunk-NSBPE2FW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-NSBPE2FW.js"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { encodeAddress } from './chunk-UDIXYJXC.js';
|
|
2
|
+
import HDKey from 'micro-key-producer/slip10.js';
|
|
3
|
+
import { generateMnemonic, validateMnemonic, mnemonicToSeedSync } from '@scure/bip39';
|
|
4
|
+
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
5
|
+
|
|
6
|
+
var _ThruHDWallet = class _ThruHDWallet {
|
|
7
|
+
static ensureSeed(seed) {
|
|
8
|
+
if (seed.length !== 64) {
|
|
9
|
+
throw new Error("Seed must be 64 bytes");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
static deriveKeyPair(seed, path) {
|
|
13
|
+
_ThruHDWallet.ensureSeed(seed);
|
|
14
|
+
const hdkey = HDKey.fromMasterSeed(seed);
|
|
15
|
+
const derived = hdkey.derive(path);
|
|
16
|
+
if (!derived.privateKey || !derived.publicKey) {
|
|
17
|
+
throw new Error("Failed to derive key pair");
|
|
18
|
+
}
|
|
19
|
+
const privateKey = derived.privateKey;
|
|
20
|
+
const publicKey = derived.publicKeyRaw;
|
|
21
|
+
const secretKey = new Uint8Array(privateKey.length + publicKey.length);
|
|
22
|
+
secretKey.set(privateKey, 0);
|
|
23
|
+
secretKey.set(publicKey, privateKey.length);
|
|
24
|
+
return {
|
|
25
|
+
publicKey,
|
|
26
|
+
privateKey,
|
|
27
|
+
secretKey
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
static async getAccount(seed, accountIndex = 0, change = 0) {
|
|
31
|
+
if (accountIndex < 0) {
|
|
32
|
+
throw new Error("Account index must be non-negative");
|
|
33
|
+
}
|
|
34
|
+
const path = `${_ThruHDWallet.THRU_DERIVATION_PATH}/${accountIndex}'/${change}'`;
|
|
35
|
+
const { publicKey, privateKey, secretKey } = _ThruHDWallet.deriveKeyPair(seed, path);
|
|
36
|
+
return {
|
|
37
|
+
address: encodeAddress(publicKey),
|
|
38
|
+
publicKey,
|
|
39
|
+
privateKey,
|
|
40
|
+
secretKey,
|
|
41
|
+
path
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
static async deriveAccounts(seed, count) {
|
|
45
|
+
const accounts = [];
|
|
46
|
+
for (let i = 0; i < count; i++) {
|
|
47
|
+
const account = await _ThruHDWallet.getAccount(seed, i);
|
|
48
|
+
accounts.push({
|
|
49
|
+
index: i,
|
|
50
|
+
address: account.address,
|
|
51
|
+
path: account.path,
|
|
52
|
+
publicKey: account.publicKey
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return accounts;
|
|
56
|
+
}
|
|
57
|
+
static isValidPath(path) {
|
|
58
|
+
const pathRegex = /^m(\/\d+')+$/;
|
|
59
|
+
return pathRegex.test(path);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
_ThruHDWallet.THRU_COIN_TYPE = 9999;
|
|
63
|
+
_ThruHDWallet.THRU_DERIVATION_PATH = `m/44'/${_ThruHDWallet.THRU_COIN_TYPE}'`;
|
|
64
|
+
var ThruHDWallet = _ThruHDWallet;
|
|
65
|
+
var MnemonicGenerator = class {
|
|
66
|
+
/**
|
|
67
|
+
* Generate a new 12-word mnemonic phrase
|
|
68
|
+
* @returns 12-word mnemonic string
|
|
69
|
+
*/
|
|
70
|
+
static generate() {
|
|
71
|
+
return generateMnemonic(wordlist, 128);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Validate a mnemonic phrase
|
|
75
|
+
* @param phrase - Mnemonic phrase to validate
|
|
76
|
+
* @returns true if valid, false otherwise
|
|
77
|
+
*/
|
|
78
|
+
static validate(phrase) {
|
|
79
|
+
return validateMnemonic(phrase, wordlist);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Convert mnemonic phrase to seed bytes
|
|
83
|
+
* @param phrase - Valid mnemonic phrase
|
|
84
|
+
* @param passphrase - Optional passphrase for additional security
|
|
85
|
+
* @returns Seed as Uint8Array (64 bytes)
|
|
86
|
+
*/
|
|
87
|
+
static toSeed(phrase, passphrase = "") {
|
|
88
|
+
if (!this.validate(phrase)) {
|
|
89
|
+
throw new Error("Invalid mnemonic phrase");
|
|
90
|
+
}
|
|
91
|
+
return mnemonicToSeedSync(phrase, passphrase);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the number of words in a mnemonic
|
|
95
|
+
* @param phrase - Mnemonic phrase
|
|
96
|
+
* @returns Number of words
|
|
97
|
+
*/
|
|
98
|
+
static getWordCount(phrase) {
|
|
99
|
+
return phrase.trim().split(/\s+/).length;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export { MnemonicGenerator, ThruHDWallet };
|
|
104
|
+
//# sourceMappingURL=chunk-RL3Q6FDE.js.map
|
|
105
|
+
//# sourceMappingURL=chunk-RL3Q6FDE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/crypto/hdwallet.ts","../src/crypto/mnemonic.ts"],"names":[],"mappings":";;;;;AAQO,IAAM,aAAA,GAAN,MAAM,aAAA,CAAa;AAAA,EAIxB,OAAe,WAAW,IAAA,EAAwB;AAChD,IAAA,IAAI,IAAA,CAAK,WAAW,EAAA,EAAI;AACtB,MAAA,MAAM,IAAI,M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GAAqB,EAAA,EAAgB;AACjE,IAAA,IAAI,CAAC,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA,EAAG;AAC1B,MAAA,MAAM,IAAI,MAAM,yBAAyB,CAAA;AAAA,IAC3C;AAEA,IAAA,OAAO,kBAAA,CAAmB,QAAQ,UAAU,CAAA;AAAA,EAC9C;AAAA;AAAA;AAAA;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":"chunk-RL3Q6FDE.js","sourcesContent":["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,260 @@
|
|
|
1
|
+
// src/helpers/constants.ts
|
|
2
|
+
var BASE64_URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
3
|
+
var tempMap = new Int16Array(256).fill(-1);
|
|
4
|
+
for (let i = 0; i < BASE64_URL_ALPHABET.length; i++) {
|
|
5
|
+
tempMap[BASE64_URL_ALPHABET.charCodeAt(i)] = i;
|
|
6
|
+
}
|
|
7
|
+
var BASE64_URL_MAP = tempMap;
|
|
8
|
+
|
|
9
|
+
// src/helpers/address.ts
|
|
10
|
+
function encodeAddress(bytes) {
|
|
11
|
+
if (bytes.length !== 32) {
|
|
12
|
+
throw new Error("Expected 32-byte address");
|
|
13
|
+
}
|
|
14
|
+
let checksum = 0;
|
|
15
|
+
let accumulator = 0;
|
|
16
|
+
let bitsCollected = 0;
|
|
17
|
+
const output = ["t", "a"];
|
|
18
|
+
for (let i = 0; i < 30; i++) {
|
|
19
|
+
const byte = bytes[i];
|
|
20
|
+
checksum += byte;
|
|
21
|
+
accumulator = (accumulator << 8 | byte) >>> 0;
|
|
22
|
+
bitsCollected += 8;
|
|
23
|
+
while (bitsCollected >= 6) {
|
|
24
|
+
const index = accumulator >> bitsCollected - 6 & 63;
|
|
25
|
+
output.push(BASE64_URL_ALPHABET[index]);
|
|
26
|
+
bitsCollected -= 6;
|
|
27
|
+
accumulator &= maskForBits(bitsCollected);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const secondLast = bytes[30];
|
|
31
|
+
checksum += secondLast;
|
|
32
|
+
accumulator = (accumulator << 8 | secondLast) >>> 0;
|
|
33
|
+
bitsCollected += 8;
|
|
34
|
+
const last = bytes[31];
|
|
35
|
+
checksum += last;
|
|
36
|
+
accumulator = (accumulator << 8 | last) >>> 0;
|
|
37
|
+
bitsCollected += 8;
|
|
38
|
+
accumulator = (accumulator << 8 | checksum & 255) >>> 0;
|
|
39
|
+
bitsCollected += 8;
|
|
40
|
+
while (bitsCollected >= 6) {
|
|
41
|
+
const index = accumulator >> bitsCollected - 6 & 63;
|
|
42
|
+
output.push(BASE64_URL_ALPHABET[index]);
|
|
43
|
+
bitsCollected -= 6;
|
|
44
|
+
accumulator &= maskForBits(bitsCollected);
|
|
45
|
+
}
|
|
46
|
+
return output.join("");
|
|
47
|
+
}
|
|
48
|
+
function decodeAddress(value) {
|
|
49
|
+
if (value.length !== 46) {
|
|
50
|
+
throw new Error("Invalid address length");
|
|
51
|
+
}
|
|
52
|
+
if (!value.startsWith("ta")) {
|
|
53
|
+
throw new Error('Address must start with "ta"');
|
|
54
|
+
}
|
|
55
|
+
const output = new Uint8Array(32);
|
|
56
|
+
let checksum = 0;
|
|
57
|
+
let inIdx = 2;
|
|
58
|
+
let remaining = 40;
|
|
59
|
+
let outIdx = 0;
|
|
60
|
+
while (remaining >= 4) {
|
|
61
|
+
const a2 = BASE64_URL_MAP[value.charCodeAt(inIdx)];
|
|
62
|
+
const b2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];
|
|
63
|
+
const c2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];
|
|
64
|
+
const d2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];
|
|
65
|
+
if (a2 < 0 || b2 < 0 || c2 < 0 || d2 < 0) {
|
|
66
|
+
throw new Error("Invalid address encoding");
|
|
67
|
+
}
|
|
68
|
+
const triple2 = a2 << 18 | b2 << 12 | c2 << 6 | d2;
|
|
69
|
+
const byte12 = triple2 >> 16 & 255;
|
|
70
|
+
const byte22 = triple2 >> 8 & 255;
|
|
71
|
+
const byte3 = triple2 & 255;
|
|
72
|
+
checksum += byte12;
|
|
73
|
+
checksum += byte22;
|
|
74
|
+
checksum += byte3;
|
|
75
|
+
output[outIdx++] = byte12;
|
|
76
|
+
output[outIdx++] = byte22;
|
|
77
|
+
output[outIdx++] = byte3;
|
|
78
|
+
inIdx += 4;
|
|
79
|
+
remaining -= 4;
|
|
80
|
+
}
|
|
81
|
+
const a = BASE64_URL_MAP[value.charCodeAt(inIdx)];
|
|
82
|
+
const b = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];
|
|
83
|
+
const c = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];
|
|
84
|
+
const d = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];
|
|
85
|
+
if (a < 0 || b < 0 || c < 0 || d < 0) {
|
|
86
|
+
throw new Error("Invalid address encoding");
|
|
87
|
+
}
|
|
88
|
+
const triple = a << 18 | b << 12 | c << 6 | d;
|
|
89
|
+
const byte1 = triple >> 16 & 255;
|
|
90
|
+
const byte2 = triple >> 8 & 255;
|
|
91
|
+
const incomingChecksum = triple & 255;
|
|
92
|
+
checksum += byte1;
|
|
93
|
+
checksum += byte2;
|
|
94
|
+
output[outIdx++] = byte1;
|
|
95
|
+
output[outIdx++] = byte2;
|
|
96
|
+
checksum &= 255;
|
|
97
|
+
if (checksum !== incomingChecksum) {
|
|
98
|
+
throw new Error("Address checksum mismatch");
|
|
99
|
+
}
|
|
100
|
+
return output;
|
|
101
|
+
}
|
|
102
|
+
function maskForBits(bits) {
|
|
103
|
+
return bits === 0 ? 0 : (1 << bits) - 1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/helpers/encoding.ts
|
|
107
|
+
function decodeBase64(value) {
|
|
108
|
+
if (value.length === 0) {
|
|
109
|
+
return new Uint8Array();
|
|
110
|
+
}
|
|
111
|
+
const atobFn = globalThis.atob;
|
|
112
|
+
if (!atobFn) {
|
|
113
|
+
throw new Error("Base64 decoding requires globalThis.atob support");
|
|
114
|
+
}
|
|
115
|
+
const binary = atobFn(value);
|
|
116
|
+
const bytes = new Uint8Array(binary.length);
|
|
117
|
+
for (let i = 0; i < binary.length; i++) {
|
|
118
|
+
bytes[i] = binary.charCodeAt(i);
|
|
119
|
+
}
|
|
120
|
+
return bytes;
|
|
121
|
+
}
|
|
122
|
+
function hexToBytes(value) {
|
|
123
|
+
const normalized = value.startsWith("0x") ? value.slice(2) : value;
|
|
124
|
+
if (normalized.length % 2 !== 0) {
|
|
125
|
+
throw new Error("Hex string must contain an even number of characters");
|
|
126
|
+
}
|
|
127
|
+
const bytes = new Uint8Array(normalized.length / 2);
|
|
128
|
+
for (let i = 0; i < normalized.length; i += 2) {
|
|
129
|
+
const byte = parseInt(normalized.slice(i, i + 2), 16);
|
|
130
|
+
if (Number.isNaN(byte)) {
|
|
131
|
+
throw new Error("Hex string contains invalid characters");
|
|
132
|
+
}
|
|
133
|
+
bytes[i / 2] = byte;
|
|
134
|
+
}
|
|
135
|
+
return bytes;
|
|
136
|
+
}
|
|
137
|
+
function isHexString(value) {
|
|
138
|
+
const normalized = value.startsWith("0x") ? value.slice(2) : value;
|
|
139
|
+
return normalized.length % 2 === 0 && normalized.length > 0 && /^[0-9a-fA-F]+$/.test(normalized);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/helpers/utils.ts
|
|
143
|
+
function ensureBytes(value, field) {
|
|
144
|
+
if (value instanceof Uint8Array) {
|
|
145
|
+
if (value.length === 0) {
|
|
146
|
+
throw new Error(`${field} cannot be empty`);
|
|
147
|
+
}
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
if (typeof value === "string") {
|
|
151
|
+
if (value.length === 0) {
|
|
152
|
+
throw new Error(`${field} cannot be empty`);
|
|
153
|
+
}
|
|
154
|
+
return decodeBase64(value);
|
|
155
|
+
}
|
|
156
|
+
throw new Error(`${field} is required`);
|
|
157
|
+
}
|
|
158
|
+
function maskForBits2(bits) {
|
|
159
|
+
return bits === 0 ? 0 : (1 << bits) - 1;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/helpers/signature.ts
|
|
163
|
+
function encodeSignature(bytes) {
|
|
164
|
+
if (bytes.length !== 64) {
|
|
165
|
+
throw new Error("Expected 64-byte signature");
|
|
166
|
+
}
|
|
167
|
+
let checksum = 0;
|
|
168
|
+
let accumulator = 0;
|
|
169
|
+
let bitsCollected = 0;
|
|
170
|
+
const output = ["t", "s"];
|
|
171
|
+
for (let i = 0; i < 63; i++) {
|
|
172
|
+
const byte = bytes[i];
|
|
173
|
+
checksum += byte;
|
|
174
|
+
accumulator = (accumulator << 8 | byte) >>> 0;
|
|
175
|
+
bitsCollected += 8;
|
|
176
|
+
while (bitsCollected >= 6) {
|
|
177
|
+
const index = accumulator >> bitsCollected - 6 & 63;
|
|
178
|
+
output.push(BASE64_URL_ALPHABET[index]);
|
|
179
|
+
bitsCollected -= 6;
|
|
180
|
+
accumulator &= maskForBits2(bitsCollected);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const lastByte = bytes[63];
|
|
184
|
+
checksum += lastByte;
|
|
185
|
+
accumulator = (accumulator << 8 | lastByte) >>> 0;
|
|
186
|
+
bitsCollected += 8;
|
|
187
|
+
accumulator = (accumulator << 16 | checksum & 65535) >>> 0;
|
|
188
|
+
bitsCollected += 16;
|
|
189
|
+
while (bitsCollected >= 6) {
|
|
190
|
+
const index = accumulator >> bitsCollected - 6 & 63;
|
|
191
|
+
output.push(BASE64_URL_ALPHABET[index]);
|
|
192
|
+
bitsCollected -= 6;
|
|
193
|
+
accumulator &= maskForBits2(bitsCollected);
|
|
194
|
+
}
|
|
195
|
+
return output.join("");
|
|
196
|
+
}
|
|
197
|
+
function decodeSignature(value) {
|
|
198
|
+
if (value.length !== 90) {
|
|
199
|
+
throw new Error("Invalid signature length");
|
|
200
|
+
}
|
|
201
|
+
if (!value.startsWith("ts")) {
|
|
202
|
+
throw new Error('Signature must start with "ts"');
|
|
203
|
+
}
|
|
204
|
+
const output = new Uint8Array(64);
|
|
205
|
+
let checksum = 0;
|
|
206
|
+
let inIdx = 2;
|
|
207
|
+
let remaining = 84;
|
|
208
|
+
let outIdx = 0;
|
|
209
|
+
while (remaining > 0) {
|
|
210
|
+
const a2 = BASE64_URL_MAP[value.charCodeAt(inIdx)];
|
|
211
|
+
const b2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];
|
|
212
|
+
const c2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];
|
|
213
|
+
const d2 = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];
|
|
214
|
+
if (a2 < 0 || b2 < 0 || c2 < 0 || d2 < 0) {
|
|
215
|
+
throw new Error("Invalid signature encoding");
|
|
216
|
+
}
|
|
217
|
+
const triple2 = a2 << 18 | b2 << 12 | c2 << 6 | d2;
|
|
218
|
+
const byte1 = triple2 >> 16 & 255;
|
|
219
|
+
const byte2 = triple2 >> 8 & 255;
|
|
220
|
+
const byte3 = triple2 & 255;
|
|
221
|
+
checksum += byte1;
|
|
222
|
+
checksum += byte2;
|
|
223
|
+
checksum += byte3;
|
|
224
|
+
output[outIdx++] = byte1;
|
|
225
|
+
output[outIdx++] = byte2;
|
|
226
|
+
output[outIdx++] = byte3;
|
|
227
|
+
inIdx += 4;
|
|
228
|
+
remaining -= 4;
|
|
229
|
+
}
|
|
230
|
+
const a = BASE64_URL_MAP[value.charCodeAt(inIdx)];
|
|
231
|
+
const b = BASE64_URL_MAP[value.charCodeAt(inIdx + 1)];
|
|
232
|
+
const c = BASE64_URL_MAP[value.charCodeAt(inIdx + 2)];
|
|
233
|
+
const d = BASE64_URL_MAP[value.charCodeAt(inIdx + 3)];
|
|
234
|
+
if (a < 0 || b < 0 || c < 0 || d < 0) {
|
|
235
|
+
throw new Error("Invalid signature encoding");
|
|
236
|
+
}
|
|
237
|
+
const triple = a << 18 | b << 12 | c << 6 | d;
|
|
238
|
+
const finalByte = triple >> 16 & 255;
|
|
239
|
+
checksum += finalByte;
|
|
240
|
+
output[outIdx] = finalByte;
|
|
241
|
+
const incomingChecksum = triple & 65535;
|
|
242
|
+
checksum &= 65535;
|
|
243
|
+
if (checksum !== incomingChecksum) {
|
|
244
|
+
throw new Error("Signature checksum mismatch");
|
|
245
|
+
}
|
|
246
|
+
return output;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// src/helpers/webcrypto.ts
|
|
250
|
+
function getWebCrypto() {
|
|
251
|
+
const cryptoObj = typeof globalThis !== "undefined" ? globalThis.crypto : void 0;
|
|
252
|
+
if (cryptoObj && typeof cryptoObj.getRandomValues === "function") {
|
|
253
|
+
return cryptoObj;
|
|
254
|
+
}
|
|
255
|
+
throw new Error("Web Crypto API is unavailable. Provide a polyfill exposing globalThis.crypto.");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { decodeAddress, decodeBase64, decodeSignature, encodeAddress, encodeSignature, ensureBytes, getWebCrypto, hexToBytes, isHexString };
|
|
259
|
+
//# sourceMappingURL=chunk-UDIXYJXC.js.map
|
|
260
|
+
//# sourceMappingURL=chunk-UDIXYJXC.js.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,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(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"]}
|