@totemsdk/core 1.2.0 → 1.2.1
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/bip39.js +2 -2
- package/dist/javaStreamables.js +8 -8
- package/dist/minima32.js +3 -3
- package/dist/mmr.js +2 -2
- package/dist/scripts/contract-helpers.js +12 -10
- package/dist/scripts/witness-serializer.js +2 -2
- package/dist/transaction.js +3 -3
- package/dist/verify.js +3 -3
- package/dist/wots.d.ts +2 -2
- package/dist/wots.js +2 -2
- package/package.json +1 -10
package/dist/bip39.js
CHANGED
|
@@ -21,7 +21,7 @@ exports.convertWordListToSeed = convertWordListToSeed;
|
|
|
21
21
|
exports.phraseToSeed = phraseToSeed;
|
|
22
22
|
exports.generateWordList = generateWordList;
|
|
23
23
|
exports.generateSeedPhrase = generateSeedPhrase;
|
|
24
|
-
const
|
|
24
|
+
const wasm_sync_js_1 = require("./wasm-sync.js");
|
|
25
25
|
/**
|
|
26
26
|
* Official BIP39 English word list (2048 words)
|
|
27
27
|
* From https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt
|
|
@@ -364,7 +364,7 @@ function validatePhrase(phrase) {
|
|
|
364
364
|
function convertStringToSeed(phrase) {
|
|
365
365
|
const encoder = new TextEncoder();
|
|
366
366
|
const phraseBytes = encoder.encode(phrase);
|
|
367
|
-
return (0,
|
|
367
|
+
return (0, wasm_sync_js_1.sha3_256)(phraseBytes);
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
370
|
* Convert word array to seed matching Minima's BIP39.convertWordListToSeed()
|
package/dist/javaStreamables.js
CHANGED
|
@@ -33,7 +33,7 @@ exports.serializeMMREntry = serializeMMREntry;
|
|
|
33
33
|
exports.deriveRootPrivSeed = deriveRootPrivSeed;
|
|
34
34
|
exports.deriveUnifiedChildSeed = deriveUnifiedChildSeed;
|
|
35
35
|
exports.precomputeTransactionCoinID = precomputeTransactionCoinID;
|
|
36
|
-
const
|
|
36
|
+
const wasm_sync_js_1 = require("./wasm-sync.js");
|
|
37
37
|
const Streamable_js_1 = require("./Streamable.js");
|
|
38
38
|
/**
|
|
39
39
|
* Serialize a number in MiniNumber format (Java compatible)
|
|
@@ -82,7 +82,7 @@ function hashAllObjects(...items) {
|
|
|
82
82
|
offset += item.length;
|
|
83
83
|
}
|
|
84
84
|
// SHA3-256 hash
|
|
85
|
-
return (0,
|
|
85
|
+
return (0, wasm_sync_js_1.sha3_256)(combined);
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
88
|
* Derive per-chain seed matching Java TreeKeyNode.java exactly
|
|
@@ -130,7 +130,7 @@ function deriveChildTreeSeedJava(childSeed, childIndex) {
|
|
|
130
130
|
*/
|
|
131
131
|
function hashObject(data) {
|
|
132
132
|
const serialized = serializeMiniData(data);
|
|
133
|
-
return (0,
|
|
133
|
+
return (0, wasm_sync_js_1.sha3_256)(serialized);
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* Convert index to MiniData bytes matching Java's:
|
|
@@ -180,7 +180,7 @@ function derivePerAddressSeed(baseSeed, addressIndex) {
|
|
|
180
180
|
const combined = new Uint8Array(baseSeedSerialized.length + modifierSerialized.length);
|
|
181
181
|
combined.set(baseSeedSerialized, 0);
|
|
182
182
|
combined.set(modifierSerialized, baseSeedSerialized.length);
|
|
183
|
-
const result = (0,
|
|
183
|
+
const result = (0, wasm_sync_js_1.sha3_256)(combined);
|
|
184
184
|
// DIAGNOSTIC: Log first 8 bytes to detect bundle duplication or implementation differences
|
|
185
185
|
// Enable via: globalThis.TOTEM_SEED_DEBUG = true
|
|
186
186
|
if (typeof console !== 'undefined' && globalThis.TOTEM_SEED_DEBUG) {
|
|
@@ -240,7 +240,7 @@ function javaHashAllObjects(...items) {
|
|
|
240
240
|
combined.set(item, offset);
|
|
241
241
|
offset += item.length;
|
|
242
242
|
}
|
|
243
|
-
return (0,
|
|
243
|
+
return (0, wasm_sync_js_1.sha3_256)(combined);
|
|
244
244
|
}
|
|
245
245
|
/**
|
|
246
246
|
* Create MMREntryNumber from bigint (common case for integer positions)
|
|
@@ -334,7 +334,7 @@ function deriveRootPrivSeed(baseSeed) {
|
|
|
334
334
|
const combined = new Uint8Array(baseSeedSerialized.length + rootIdentitySerialized.length);
|
|
335
335
|
combined.set(baseSeedSerialized, 0);
|
|
336
336
|
combined.set(rootIdentitySerialized, baseSeedSerialized.length);
|
|
337
|
-
return (0,
|
|
337
|
+
return (0, wasm_sync_js_1.sha3_256)(combined);
|
|
338
338
|
}
|
|
339
339
|
/**
|
|
340
340
|
* Derive a unified child seed for the address at `index`.
|
|
@@ -354,7 +354,7 @@ function deriveUnifiedChildSeed(baseSeed, index) {
|
|
|
354
354
|
const combined = new Uint8Array(rootSeedSerialized.length + modifierSerialized.length);
|
|
355
355
|
combined.set(rootSeedSerialized, 0);
|
|
356
356
|
combined.set(modifierSerialized, rootSeedSerialized.length);
|
|
357
|
-
return (0,
|
|
357
|
+
return (0, wasm_sync_js_1.sha3_256)(combined);
|
|
358
358
|
}
|
|
359
359
|
/**
|
|
360
360
|
* Precompute output coin IDs before computing the transaction digest.
|
|
@@ -386,6 +386,6 @@ function precomputeTransactionCoinID(inputs, outputs) {
|
|
|
386
386
|
const combined = new Uint8Array(baseCoinIdStream.length + outputIndexStream.length);
|
|
387
387
|
combined.set(baseCoinIdStream, 0);
|
|
388
388
|
combined.set(outputIndexStream, baseCoinIdStream.length);
|
|
389
|
-
outputs[i].coinId = (0,
|
|
389
|
+
outputs[i].coinId = (0, wasm_sync_js_1.sha3_256)(combined);
|
|
390
390
|
}
|
|
391
391
|
}
|
package/dist/minima32.js
CHANGED
|
@@ -48,7 +48,7 @@ function decodeMxRadix32Frame(mx) {
|
|
|
48
48
|
}
|
|
49
49
|
return bigIntToBytes(x);
|
|
50
50
|
}
|
|
51
|
-
const
|
|
51
|
+
const wasm_sync_js_1 = require("./wasm-sync.js");
|
|
52
52
|
/** Encode raw 32 bytes to Mx address with frame and checksum */
|
|
53
53
|
function makeMxAddress(root32) {
|
|
54
54
|
if (root32.length !== 32) {
|
|
@@ -61,7 +61,7 @@ function makeMxAddress(root32) {
|
|
|
61
61
|
frame[2] = 32; // Length low byte
|
|
62
62
|
frame.set(root32, 3);
|
|
63
63
|
// Calculate checksum of the raw 32 bytes
|
|
64
|
-
const chk = (0,
|
|
64
|
+
const chk = (0, wasm_sync_js_1.sha3_256)(root32);
|
|
65
65
|
frame.set(chk.slice(0, 4), 35);
|
|
66
66
|
return encodeMxRadix32Frame(frame);
|
|
67
67
|
}
|
|
@@ -79,7 +79,7 @@ function parseMxAddress(mx) {
|
|
|
79
79
|
const root32 = frame.slice(3, 35);
|
|
80
80
|
const checksum = frame.slice(35, 39);
|
|
81
81
|
// Validate checksum
|
|
82
|
-
const expectedChk = (0,
|
|
82
|
+
const expectedChk = (0, wasm_sync_js_1.sha3_256)(root32);
|
|
83
83
|
const expected = expectedChk.slice(0, 4);
|
|
84
84
|
for (let i = 0; i < 4; i++) {
|
|
85
85
|
if (checksum[i] !== expected[i]) {
|
package/dist/mmr.js
CHANGED
|
@@ -11,7 +11,7 @@ exports.verifyMMRProof = verifyMMRProof;
|
|
|
11
11
|
exports.parseMMRProofFromHex = parseMMRProofFromHex;
|
|
12
12
|
// packages/totem-sdk/packages/core/src/mmr.ts
|
|
13
13
|
// Full MMR implementation matching Minima's MMR.java, MMRData.java, and TreeKeyNode.java
|
|
14
|
-
const
|
|
14
|
+
const wasm_sync_js_1 = require("./wasm-sync.js");
|
|
15
15
|
const javaStreamables_js_1 = require("./javaStreamables.js");
|
|
16
16
|
// Import canonical wire serialization from Streamable.ts (single source of truth)
|
|
17
17
|
const Streamable_js_1 = require("./Streamable.js");
|
|
@@ -31,7 +31,7 @@ function serializeMMRProof(proof, blockTime = 0n) {
|
|
|
31
31
|
exports.serializeRealMMRProof = serializeMMRProof;
|
|
32
32
|
/** SHA3-256 helper returning 32 bytes */
|
|
33
33
|
function sha3(data) {
|
|
34
|
-
return (0,
|
|
34
|
+
return (0, wasm_sync_js_1.sha3_256)(data);
|
|
35
35
|
}
|
|
36
36
|
/** concat utility */
|
|
37
37
|
function concat(...parts) {
|
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.StatefulGameHelper = exports.SlowCashHelper = exports.FlashCashHelper = exports.VaultHelper = exports.ExchangeHelper = exports.MASTHelper = exports.HTLCHelper = exports.TimelockHelper = void 0;
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
19
|
+
const wasm_sync_js_1 = require("../wasm-sync.js");
|
|
20
|
+
const node_crypto_1 = require("node:crypto");
|
|
21
|
+
function sha256(data) {
|
|
22
|
+
return new Uint8Array((0, node_crypto_1.createHash)('sha256').update(data).digest());
|
|
23
|
+
}
|
|
22
24
|
const types_js_1 = require("./types.js");
|
|
23
25
|
function kissHex(hex) {
|
|
24
26
|
const raw = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
|
|
@@ -81,9 +83,9 @@ class HTLCHelper {
|
|
|
81
83
|
* Generate a random preimage and its hash.
|
|
82
84
|
*/
|
|
83
85
|
static generateSecret() {
|
|
84
|
-
const preimageBytes = (0,
|
|
86
|
+
const preimageBytes = (0, node_crypto_1.randomBytes)(32);
|
|
85
87
|
const preimage = bytesToHex(preimageBytes);
|
|
86
|
-
const hashBytes = (0,
|
|
88
|
+
const hashBytes = (0, wasm_sync_js_1.sha3_256)(preimageBytes);
|
|
87
89
|
const hash = bytesToHex(hashBytes);
|
|
88
90
|
return { preimage, hash };
|
|
89
91
|
}
|
|
@@ -93,11 +95,11 @@ class HTLCHelper {
|
|
|
93
95
|
static hashPreimage(preimage, algorithm = 'sha3') {
|
|
94
96
|
const preimageBytes = hexToBytes(preimage);
|
|
95
97
|
if (algorithm === 'sha2') {
|
|
96
|
-
const hashBytes =
|
|
98
|
+
const hashBytes = sha256(preimageBytes);
|
|
97
99
|
return bytesToHex(hashBytes);
|
|
98
100
|
}
|
|
99
101
|
else {
|
|
100
|
-
const hashBytes = (0,
|
|
102
|
+
const hashBytes = (0, wasm_sync_js_1.sha3_256)(preimageBytes);
|
|
101
103
|
return bytesToHex(hashBytes);
|
|
102
104
|
}
|
|
103
105
|
}
|
|
@@ -146,7 +148,7 @@ class MASTHelper {
|
|
|
146
148
|
*/
|
|
147
149
|
static hashScript(script) {
|
|
148
150
|
const scriptBytes = new TextEncoder().encode(script.trim().toUpperCase());
|
|
149
|
-
const hashBytes = (0,
|
|
151
|
+
const hashBytes = (0, wasm_sync_js_1.sha3_256)(scriptBytes);
|
|
150
152
|
return bytesToHex(hashBytes);
|
|
151
153
|
}
|
|
152
154
|
/**
|
|
@@ -177,7 +179,7 @@ class MASTHelper {
|
|
|
177
179
|
proofs.set(scripts[i], { proof: proofHex, index: i });
|
|
178
180
|
}
|
|
179
181
|
const combinedBytes = hexToBytes(hashes[0].slice(2) + hashes[1].slice(2));
|
|
180
|
-
const rootBytes = (0,
|
|
182
|
+
const rootBytes = (0, wasm_sync_js_1.sha3_256)(combinedBytes);
|
|
181
183
|
const root = bytesToHex(rootBytes);
|
|
182
184
|
return { root, proofs };
|
|
183
185
|
}
|
|
@@ -390,7 +392,7 @@ exports.StatefulGameHelper = StatefulGameHelper;
|
|
|
390
392
|
function computeScriptAddress(script) {
|
|
391
393
|
const cleanScript = script.trim().toUpperCase();
|
|
392
394
|
const scriptBytes = new TextEncoder().encode(cleanScript);
|
|
393
|
-
const hashBytes = (0,
|
|
395
|
+
const hashBytes = (0, wasm_sync_js_1.sha3_256)(scriptBytes);
|
|
394
396
|
return bytesToHex(hashBytes);
|
|
395
397
|
}
|
|
396
398
|
function encodeSimpleProof(siblingHash, isLeft) {
|
|
@@ -17,7 +17,7 @@ exports.aggregateSignatures = aggregateSignatures;
|
|
|
17
17
|
exports.validateExternalSignature = validateExternalSignature;
|
|
18
18
|
exports.computeScriptAddress = computeScriptAddress;
|
|
19
19
|
exports.concat = concat;
|
|
20
|
-
const
|
|
20
|
+
const wasm_sync_js_1 = require("../wasm-sync.js");
|
|
21
21
|
const mmr_js_1 = require("../mmr.js");
|
|
22
22
|
const minima32_js_1 = require("../minima32.js");
|
|
23
23
|
function hexToBytes(hex) {
|
|
@@ -301,6 +301,6 @@ function validateExternalSignature(signature, transactionDigest) {
|
|
|
301
301
|
function computeScriptAddress(script) {
|
|
302
302
|
const cleanScript = script.trim().toUpperCase();
|
|
303
303
|
const scriptBytes = new TextEncoder().encode(cleanScript);
|
|
304
|
-
const hashBytes = (0,
|
|
304
|
+
const hashBytes = (0, wasm_sync_js_1.sha3_256)(scriptBytes);
|
|
305
305
|
return bytesToHex(hashBytes);
|
|
306
306
|
}
|
package/dist/transaction.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.computeTransactionDigest = computeTransactionDigest;
|
|
|
19
19
|
exports.precomputeTransactionCoinID = precomputeTransactionCoinID;
|
|
20
20
|
exports.createDefaultTransaction = createDefaultTransaction;
|
|
21
21
|
exports.buildMinimaCoin = buildMinimaCoin;
|
|
22
|
-
const
|
|
22
|
+
const wasm_sync_js_1 = require("./wasm-sync.js");
|
|
23
23
|
const Streamable_js_1 = require("./Streamable.js");
|
|
24
24
|
const ZERO_TXPOWID = new Uint8Array([0x00]);
|
|
25
25
|
const STATETYPE_HEX = 1;
|
|
@@ -231,7 +231,7 @@ function serializeTransaction(tx) {
|
|
|
231
231
|
}
|
|
232
232
|
function computeTransactionDigest(tx) {
|
|
233
233
|
const serialized = serializeTransaction(tx);
|
|
234
|
-
return (0,
|
|
234
|
+
return (0, wasm_sync_js_1.sha3_256)(serialized);
|
|
235
235
|
}
|
|
236
236
|
function precomputeTransactionCoinID(tx) {
|
|
237
237
|
if (tx.inputs.length === 0)
|
|
@@ -245,7 +245,7 @@ function precomputeTransactionCoinID(tx) {
|
|
|
245
245
|
const baseCoinIdStream = (0, Streamable_js_1.writeMiniData)(baseCoinId);
|
|
246
246
|
const outputIndexStream = (0, Streamable_js_1.writeMiniNumber)(BigInt(i));
|
|
247
247
|
const combined = (0, Streamable_js_1.concat)(baseCoinIdStream, outputIndexStream);
|
|
248
|
-
tx.outputs[i].coinId = (0,
|
|
248
|
+
tx.outputs[i].coinId = (0, wasm_sync_js_1.sha3_256)(combined);
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
function createDefaultTransaction() {
|
package/dist/verify.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.verifySignature = verifySignature;
|
|
|
9
9
|
exports.verifySignatureDetailed = verifySignatureDetailed;
|
|
10
10
|
exports.createChallenge = createChallenge;
|
|
11
11
|
exports.validateChallenge = validateChallenge;
|
|
12
|
-
const
|
|
12
|
+
const wasm_sync_js_1 = require("./wasm-sync.js");
|
|
13
13
|
const treekey_js_1 = require("./treekey.js");
|
|
14
14
|
const derive_js_1 = require("./derive.js");
|
|
15
15
|
const script_js_1 = require("./script.js");
|
|
@@ -107,7 +107,7 @@ function verifySignatureDetailed(address, message, signatureHex, publicKeyHex) {
|
|
|
107
107
|
error: `Malformed signature: ${e.message}`,
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
-
const digest = (0,
|
|
110
|
+
const digest = (0, wasm_sync_js_1.sha3_256)(new TextEncoder().encode(message));
|
|
111
111
|
return verifyTreeSignatureDetailed(pkBytes, digest, treeSignature);
|
|
112
112
|
}
|
|
113
113
|
catch (e) {
|
|
@@ -145,7 +145,7 @@ function cryptoRandomBytes(length) {
|
|
|
145
145
|
}
|
|
146
146
|
function createChallenge(domain, nonce) {
|
|
147
147
|
const ts = Date.now();
|
|
148
|
-
const n = nonce || bytesToHex((0,
|
|
148
|
+
const n = nonce || bytesToHex((0, wasm_sync_js_1.sha3_256)(new Uint8Array([...new TextEncoder().encode(`${domain}:${ts}:`), ...cryptoRandomBytes(16)]))).slice(0, 16);
|
|
149
149
|
return JSON.stringify({ domain, nonce: n, issuedAt: ts });
|
|
150
150
|
}
|
|
151
151
|
function validateChallenge(challenge, options) {
|
package/dist/wots.d.ts
CHANGED
|
@@ -31,14 +31,14 @@ export declare function disableWotsLogger(): void;
|
|
|
31
31
|
* Check if WOTS debug logging is enabled
|
|
32
32
|
*/
|
|
33
33
|
export declare function isWotsDebugEnabled(): boolean;
|
|
34
|
-
export declare const F: (x: Uint8Array) => Uint8Array<ArrayBufferLike
|
|
34
|
+
export declare const F: (x: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
35
35
|
export declare const hex: (u: Uint8Array) => string;
|
|
36
36
|
export declare const fromHex: (h: string) => Uint8Array;
|
|
37
37
|
export declare const concatBytes: (...arrs: Uint8Array[]) => Uint8Array<ArrayBuffer>;
|
|
38
38
|
export declare const u16be: (n: number) => Uint8Array<ArrayBuffer>;
|
|
39
39
|
export declare const u32be: (n: number) => Uint8Array<ArrayBuffer>;
|
|
40
40
|
export declare function assert32(u: Uint8Array, label?: string): void;
|
|
41
|
-
export declare const h: (x: Uint8Array) => Uint8Array<ArrayBufferLike
|
|
41
|
+
export declare const h: (x: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
42
42
|
/**
|
|
43
43
|
* GMSSRandom - BouncyCastle's stateful PRNG for WOTS chain seed derivation
|
|
44
44
|
*
|
package/dist/wots.js
CHANGED
|
@@ -35,7 +35,7 @@ exports.wotsVerify = wotsVerify;
|
|
|
35
35
|
exports.wotsVerifyDigest = wotsVerifyDigest;
|
|
36
36
|
exports.wotsPublicKeyFromSeed = wotsPublicKeyFromSeed;
|
|
37
37
|
exports.prfChainSeed = prfChainSeed;
|
|
38
|
-
const
|
|
38
|
+
const wasm_sync_js_1 = require("./wasm-sync.js");
|
|
39
39
|
const params_js_1 = require("./params.js");
|
|
40
40
|
const javaStreamables_js_1 = require("./javaStreamables.js");
|
|
41
41
|
const index_js_1 = require("./adapters/index.js");
|
|
@@ -68,7 +68,7 @@ function isWotsDebugEnabled() {
|
|
|
68
68
|
return wotsDebugEnabled;
|
|
69
69
|
}
|
|
70
70
|
// === Canonical helpers ===
|
|
71
|
-
const F = (x) => (0,
|
|
71
|
+
const F = (x) => (0, wasm_sync_js_1.sha3_256)(x);
|
|
72
72
|
exports.F = F;
|
|
73
73
|
const hex = (u) => {
|
|
74
74
|
let s = '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Core cryptographic primitives for Totem SDK — backed by Rust/WASM",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -87,19 +87,10 @@
|
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"@totemsdk/core-wasm": "^0.1.0"
|
|
89
89
|
},
|
|
90
|
-
"peerDependencies": {
|
|
91
|
-
"@noble/hashes": "^2.0.0"
|
|
92
|
-
},
|
|
93
|
-
"peerDependenciesMeta": {
|
|
94
|
-
"@noble/hashes": {
|
|
95
|
-
"optional": false
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
90
|
"engines": {
|
|
99
91
|
"node": ">=16.0.0"
|
|
100
92
|
},
|
|
101
93
|
"devDependencies": {
|
|
102
|
-
"@noble/hashes": "^2.2.0",
|
|
103
94
|
"@types/jest": "^29.0.0",
|
|
104
95
|
"@types/node": "^20.0.0",
|
|
105
96
|
"jest": "^29.0.0",
|