@totemsdk/core 1.2.11 → 1.4.0
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.md +58 -0
- package/dist/address-derivation.d.ts +36 -0
- package/dist/address-derivation.js +54 -0
- package/dist/bip39.js +1 -1
- package/dist/bytes.d.ts +11 -0
- package/dist/bytes.js +39 -0
- package/dist/canonical-hash.d.ts +1 -0
- package/dist/canonical-hash.js +12 -0
- package/dist/canonical.d.ts +6 -1
- package/dist/canonical.js +6 -5
- package/dist/cjs/address-derivation.d.ts +36 -0
- package/dist/cjs/address-derivation.js +60 -0
- package/dist/cjs/bytes.d.ts +11 -0
- package/dist/cjs/bytes.js +44 -0
- package/dist/cjs/canonical-hash.d.ts +1 -0
- package/dist/cjs/canonical-hash.js +15 -0
- package/dist/cjs/canonical.d.ts +6 -1
- package/dist/cjs/canonical.js +6 -6
- package/dist/cjs/index.d.ts +5 -2
- package/dist/cjs/index.js +60 -50
- package/dist/cjs/legacy.d.ts +15 -6
- package/dist/cjs/legacy.js +15 -6
- package/dist/cjs/mmr.d.ts +22 -0
- package/dist/cjs/mmr.js +33 -0
- package/dist/cjs/scripts/canonical.d.ts +20 -0
- package/dist/cjs/scripts/canonical.js +99 -0
- package/dist/cjs/scripts/contract-helpers.js +3 -3
- package/dist/cjs/scripts/index.d.ts +2 -1
- package/dist/cjs/scripts/index.js +4 -1
- package/dist/cjs/scripts/witness-serializer.d.ts +19 -0
- package/dist/cjs/scripts/witness-serializer.js +25 -5
- package/dist/cjs/wasm-sync.d.ts +3 -3
- package/dist/cjs/wasm-sync.js +10 -3
- package/dist/index.d.ts +5 -2
- package/dist/index.js +16 -11
- package/dist/javaStreamables.js +1 -1
- package/dist/legacy.d.ts +15 -6
- package/dist/legacy.js +15 -6
- package/dist/minima32.js +1 -1
- package/dist/mmr.d.ts +22 -0
- package/dist/mmr.js +34 -2
- package/dist/scripts/canonical.d.ts +20 -0
- package/dist/scripts/canonical.js +96 -0
- package/dist/scripts/contract-helpers.js +4 -4
- package/dist/scripts/index.d.ts +2 -1
- package/dist/scripts/index.js +2 -1
- package/dist/scripts/witness-serializer.d.ts +19 -0
- package/dist/scripts/witness-serializer.js +25 -6
- package/dist/transaction.js +1 -1
- package/dist/verify.js +1 -1
- package/dist/wasm-async.d.ts +81 -0
- package/dist/wasm-async.js +91 -0
- package/dist/wasm-sync.d.ts +3 -3
- package/dist/wasm-sync.js +7 -2
- package/dist/wots.js +1 -1
- package/package.json +47 -3
package/dist/cjs/index.js
CHANGED
|
@@ -22,8 +22,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
22
22
|
};
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.createChallenge = exports.timingSafeEqual = exports.deserializeTransaction = exports.computeTransactionDigest = exports.serializeTransaction = exports.wotsAddressFromKeypair = exports.parseMxAddress = exports.makeMxAddress = exports.cleanSeedPhrase = exports.validatePhrase = exports.generateWordList = exports.phraseToSeed = exports.verifyMMRProof = exports.mmrRootFromPublicKeys = exports.verifyTreeSignature = exports.deriveUnifiedAddressPublicKey = exports.createUnifiedRootTreeKey = exports.createUnifiedChildTreeKey = exports.precomputeTransactionCoinID = exports.writeMiniString = exports.writeMiniData = exports.writeMiniNumber = exports.deriveRootPrivSeed = exports.derivePerAddressSeed = exports.deriveChainSeedJava = exports.wotsKeypairFromSeed = exports.wotsPublicKeyFromSeed = exports.wotsPkFromSig = exports.wotsVerifyDigest = exports.wotsVerify = exports.wotsSign = exports.deriveFullPublicKey = exports.derivePKdigest = exports.hashChain = exports.expandPrivateKey = exports.sha3_256 = exports.concatBytes = exports.hexToBytes = exports.bytesToHex = exports.TransactionReceiptStore = exports.WatermarkExhaustedError = exports.TransactionLifecycleError = exports.TransactionLifecycle = exports.TransactionService = exports.flatIndexFromLanes = exports.finalizeLease = exports.prepareLease = exports.LeaseMonitor = exports.WatermarkStore = exports.LeaseStore = void 0;
|
|
25
|
-
exports.
|
|
26
|
-
exports.MINIMA_CONSTANTS = exports.bytesToUtf8 = exports.utf8ToBytes = exports.hashCanonical = exports.canonicalJson = exports.toHex = exports.wotsSignLegacy = exports.baseWWithChecksum = exports.toWinternitzDigits = exports.prfChainSeed = exports.h = exports.assert32 = exports.u32be = exports.u16be = exports.disableWotsLogger = exports.setWotsLogger = exports.fromHex = exports.hex = exports.F = exports.disableTreeKeyLogger = exports.setTreeKeyLogger = exports.createPerAddressTreeKeyAsync = exports.createPerAddressTreeKey = exports.createUnifiedChildTreeKeyAsync = exports.DEFAULT_LEVELS = void 0;
|
|
25
|
+
exports.TreeKey = exports.serializeMMREntry = exports.serializeMMRData = exports.serializeMMREntryNumber = exports.createMMREntryNumber = exports.deriveUnifiedChildSeed = exports.indexToMiniDataBytes = exports.javaHashAllObjects = exports.writeHashToStream = exports.serializeMiniNumberONE = exports.serializeMiniNumberZERO = exports.hashObject = exports.deriveChildTreeSeedJava = exports.hashAllObjects = exports.serializeMiniData = exports.serializeMiniNumber = exports.bigIntToByteArray = exports.concat = exports.writeSignatureProof = exports.writeSignature = exports.writeMMREntryNumber = exports.writeMiniByte = exports.verifyDeterministicAddress = exports.deriveAddress = exports.deriveUnifiedAddress = exports.deriveDeterministicAddress = exports.normalizeHex = exports.deriveAddressFromPublicKey = exports.verifyTreeSignatureDetailed = exports.verifySignatureDetailed = exports.verifySignature = exports.buildMinimaCoin = exports.createDefaultTransaction = exports.serializeTokenDescriptor = exports.computeTokenId = exports.serializeTransactionObject = exports.serializeCoin = exports.parseDecimalToMiniNumber = exports.MiniNumber = exports.generateSeedPhrase = exports.convertWordListToSeed = exports.convertStringToSeed = exports.WORD_LIST = exports.addressToRoot = exports.scriptToAddress = exports.toNodeScript = exports.decodeMx = exports.encodeMx = exports.scriptFromWotsPk = exports.validateChallenge = void 0;
|
|
26
|
+
exports.MINIMA_CONSTANTS = exports.bytesToUtf8 = exports.utf8ToBytes = exports.hashCanonical = exports.canonicalJson = exports.toHex = exports.wotsSignLegacy = exports.baseWWithChecksum = exports.toWinternitzDigits = exports.prfChainSeed = exports.h = exports.assert32 = exports.u32be = exports.u16be = exports.disableWotsLogger = exports.setWotsLogger = exports.fromHex = exports.hex = exports.F = exports.disableTreeKeyLogger = exports.setTreeKeyLogger = exports.createPerAddressTreeKeyAsync = exports.createPerAddressTreeKey = exports.createUnifiedChildTreeKeyAsync = exports.DEFAULT_LEVELS = exports.DEFAULT_KEYS_PER_LEVEL = exports.getRootPublicKey = exports.deserializeTreeSignature = exports.serializeTreeSignature = exports.TreeKeyNode = void 0;
|
|
27
27
|
exports.mxToHex = mxToHex;
|
|
28
28
|
// Version information for bundle duplication detection
|
|
29
29
|
__exportStar(require("./version.js"), exports);
|
|
@@ -48,37 +48,38 @@ Object.defineProperty(exports, "TransactionReceiptStore", { enumerable: true, ge
|
|
|
48
48
|
// Cryptographic primitives — backed by Rust/WASM (@totemsdk/core-wasm)
|
|
49
49
|
// ---------------------------------------------------------------------------
|
|
50
50
|
// Utilities
|
|
51
|
-
var
|
|
52
|
-
Object.defineProperty(exports, "bytesToHex", { enumerable: true, get: function () { return
|
|
53
|
-
Object.defineProperty(exports, "hexToBytes", { enumerable: true, get: function () { return
|
|
54
|
-
Object.defineProperty(exports, "concatBytes", { enumerable: true, get: function () { return
|
|
55
|
-
const
|
|
51
|
+
var bytes_js_1 = require("./bytes.js");
|
|
52
|
+
Object.defineProperty(exports, "bytesToHex", { enumerable: true, get: function () { return bytes_js_1.bytesToHex; } });
|
|
53
|
+
Object.defineProperty(exports, "hexToBytes", { enumerable: true, get: function () { return bytes_js_1.hexToBytes; } });
|
|
54
|
+
Object.defineProperty(exports, "concatBytes", { enumerable: true, get: function () { return bytes_js_1.concatBytes; } });
|
|
55
|
+
const bytes_js_2 = require("./bytes.js");
|
|
56
|
+
const wasm_sync_js_1 = require("./wasm-sync.js");
|
|
56
57
|
// SHA3-256
|
|
57
|
-
var
|
|
58
|
-
Object.defineProperty(exports, "sha3_256", { enumerable: true, get: function () { return
|
|
58
|
+
var wasm_sync_js_2 = require("./wasm-sync.js");
|
|
59
|
+
Object.defineProperty(exports, "sha3_256", { enumerable: true, get: function () { return wasm_sync_js_2.sha3_256; } });
|
|
59
60
|
// WOTS Signatures
|
|
60
|
-
var
|
|
61
|
-
Object.defineProperty(exports, "expandPrivateKey", { enumerable: true, get: function () { return
|
|
62
|
-
Object.defineProperty(exports, "hashChain", { enumerable: true, get: function () { return
|
|
63
|
-
Object.defineProperty(exports, "derivePKdigest", { enumerable: true, get: function () { return
|
|
64
|
-
Object.defineProperty(exports, "deriveFullPublicKey", { enumerable: true, get: function () { return
|
|
65
|
-
Object.defineProperty(exports, "wotsSign", { enumerable: true, get: function () { return
|
|
66
|
-
Object.defineProperty(exports, "wotsVerify", { enumerable: true, get: function () { return
|
|
67
|
-
Object.defineProperty(exports, "wotsVerifyDigest", { enumerable: true, get: function () { return
|
|
68
|
-
Object.defineProperty(exports, "wotsPkFromSig", { enumerable: true, get: function () { return
|
|
69
|
-
Object.defineProperty(exports, "wotsPublicKeyFromSeed", { enumerable: true, get: function () { return
|
|
70
|
-
Object.defineProperty(exports, "wotsKeypairFromSeed", { enumerable: true, get: function () { return
|
|
61
|
+
var wasm_sync_js_3 = require("./wasm-sync.js");
|
|
62
|
+
Object.defineProperty(exports, "expandPrivateKey", { enumerable: true, get: function () { return wasm_sync_js_3.expandPrivateKey; } });
|
|
63
|
+
Object.defineProperty(exports, "hashChain", { enumerable: true, get: function () { return wasm_sync_js_3.hashChain; } });
|
|
64
|
+
Object.defineProperty(exports, "derivePKdigest", { enumerable: true, get: function () { return wasm_sync_js_3.derivePKdigest; } });
|
|
65
|
+
Object.defineProperty(exports, "deriveFullPublicKey", { enumerable: true, get: function () { return wasm_sync_js_3.deriveFullPublicKey; } });
|
|
66
|
+
Object.defineProperty(exports, "wotsSign", { enumerable: true, get: function () { return wasm_sync_js_3.wotsSign; } });
|
|
67
|
+
Object.defineProperty(exports, "wotsVerify", { enumerable: true, get: function () { return wasm_sync_js_3.wotsVerify; } });
|
|
68
|
+
Object.defineProperty(exports, "wotsVerifyDigest", { enumerable: true, get: function () { return wasm_sync_js_3.wotsVerifyDigest; } });
|
|
69
|
+
Object.defineProperty(exports, "wotsPkFromSig", { enumerable: true, get: function () { return wasm_sync_js_3.wotsPkFromSig; } });
|
|
70
|
+
Object.defineProperty(exports, "wotsPublicKeyFromSeed", { enumerable: true, get: function () { return wasm_sync_js_3.wotsPublicKeyFromSeed; } });
|
|
71
|
+
Object.defineProperty(exports, "wotsKeypairFromSeed", { enumerable: true, get: function () { return wasm_sync_js_3.wotsKeypairFromSeed; } });
|
|
71
72
|
// WOTS Params (from params.ts — constants, no crypto)
|
|
72
73
|
__exportStar(require("./params.js"), exports);
|
|
73
74
|
// Java-Compatible Serialization
|
|
74
|
-
var
|
|
75
|
-
Object.defineProperty(exports, "deriveChainSeedJava", { enumerable: true, get: function () { return
|
|
76
|
-
Object.defineProperty(exports, "derivePerAddressSeed", { enumerable: true, get: function () { return
|
|
77
|
-
Object.defineProperty(exports, "deriveRootPrivSeed", { enumerable: true, get: function () { return
|
|
78
|
-
Object.defineProperty(exports, "writeMiniNumber", { enumerable: true, get: function () { return
|
|
79
|
-
Object.defineProperty(exports, "writeMiniData", { enumerable: true, get: function () { return
|
|
80
|
-
Object.defineProperty(exports, "writeMiniString", { enumerable: true, get: function () { return
|
|
81
|
-
Object.defineProperty(exports, "precomputeTransactionCoinID", { enumerable: true, get: function () { return
|
|
75
|
+
var wasm_sync_js_4 = require("./wasm-sync.js");
|
|
76
|
+
Object.defineProperty(exports, "deriveChainSeedJava", { enumerable: true, get: function () { return wasm_sync_js_4.deriveChainSeedJava; } });
|
|
77
|
+
Object.defineProperty(exports, "derivePerAddressSeed", { enumerable: true, get: function () { return wasm_sync_js_4.derivePerAddressSeed; } });
|
|
78
|
+
Object.defineProperty(exports, "deriveRootPrivSeed", { enumerable: true, get: function () { return wasm_sync_js_4.deriveRootPrivSeed; } });
|
|
79
|
+
Object.defineProperty(exports, "writeMiniNumber", { enumerable: true, get: function () { return wasm_sync_js_4.writeMiniNumber; } });
|
|
80
|
+
Object.defineProperty(exports, "writeMiniData", { enumerable: true, get: function () { return wasm_sync_js_4.writeMiniData; } });
|
|
81
|
+
Object.defineProperty(exports, "writeMiniString", { enumerable: true, get: function () { return wasm_sync_js_4.writeMiniString; } });
|
|
82
|
+
Object.defineProperty(exports, "precomputeTransactionCoinID", { enumerable: true, get: function () { return wasm_sync_js_4.precomputeTransactionCoinID; } });
|
|
82
83
|
// TreeKey/TreeKeyNode — WASM-backed
|
|
83
84
|
// createUnifiedChildTreeKey / createUnifiedRootTreeKey come from the TS
|
|
84
85
|
// implementation (returning a full TreeKey object with setUses/sign/getPublicKey)
|
|
@@ -89,9 +90,9 @@ Object.defineProperty(exports, "createUnifiedChildTreeKey", { enumerable: true,
|
|
|
89
90
|
Object.defineProperty(exports, "createUnifiedRootTreeKey", { enumerable: true, get: function () { return treekey_js_1.createUnifiedRootTreeKey; } });
|
|
90
91
|
Object.defineProperty(exports, "deriveUnifiedAddressPublicKey", { enumerable: true, get: function () { return treekey_js_1.deriveUnifiedAddressPublicKey; } });
|
|
91
92
|
Object.defineProperty(exports, "verifyTreeSignature", { enumerable: true, get: function () { return treekey_js_1.verifyTreeSignature; } });
|
|
92
|
-
var
|
|
93
|
-
Object.defineProperty(exports, "mmrRootFromPublicKeys", { enumerable: true, get: function () { return
|
|
94
|
-
Object.defineProperty(exports, "verifyMMRProof", { enumerable: true, get: function () { return
|
|
93
|
+
var wasm_sync_js_5 = require("./wasm-sync.js");
|
|
94
|
+
Object.defineProperty(exports, "mmrRootFromPublicKeys", { enumerable: true, get: function () { return wasm_sync_js_5.mmrRootFromPublicKeys; } });
|
|
95
|
+
Object.defineProperty(exports, "verifyMMRProof", { enumerable: true, get: function () { return wasm_sync_js_5.verifyMMRProof; } });
|
|
95
96
|
// BIP39 Seed Phrase Handling
|
|
96
97
|
// The WASM binding (wasm-sync.ts) shares the canonical 2048-word BIP39 list
|
|
97
98
|
// and Minima-compatible uppercase canonicalization with the TS implementation
|
|
@@ -104,22 +105,22 @@ Object.defineProperty(exports, "generateWordList", { enumerable: true, get: func
|
|
|
104
105
|
Object.defineProperty(exports, "validatePhrase", { enumerable: true, get: function () { return bip39_js_1.validatePhrase; } });
|
|
105
106
|
Object.defineProperty(exports, "cleanSeedPhrase", { enumerable: true, get: function () { return bip39_js_1.cleanSeedPhrase; } });
|
|
106
107
|
// Address Derivation
|
|
107
|
-
var
|
|
108
|
-
Object.defineProperty(exports, "makeMxAddress", { enumerable: true, get: function () { return
|
|
109
|
-
Object.defineProperty(exports, "parseMxAddress", { enumerable: true, get: function () { return
|
|
110
|
-
Object.defineProperty(exports, "wotsAddressFromKeypair", { enumerable: true, get: function () { return
|
|
108
|
+
var wasm_sync_js_6 = require("./wasm-sync.js");
|
|
109
|
+
Object.defineProperty(exports, "makeMxAddress", { enumerable: true, get: function () { return wasm_sync_js_6.makeMxAddress; } });
|
|
110
|
+
Object.defineProperty(exports, "parseMxAddress", { enumerable: true, get: function () { return wasm_sync_js_6.parseMxAddress; } });
|
|
111
|
+
Object.defineProperty(exports, "wotsAddressFromKeypair", { enumerable: true, get: function () { return wasm_sync_js_6.wotsAddressFromKeypair; } });
|
|
111
112
|
// Transaction Serialization & Digest
|
|
112
|
-
var
|
|
113
|
-
Object.defineProperty(exports, "serializeTransaction", { enumerable: true, get: function () { return
|
|
114
|
-
Object.defineProperty(exports, "computeTransactionDigest", { enumerable: true, get: function () { return
|
|
113
|
+
var wasm_sync_js_7 = require("./wasm-sync.js");
|
|
114
|
+
Object.defineProperty(exports, "serializeTransaction", { enumerable: true, get: function () { return wasm_sync_js_7.serializeTransaction; } });
|
|
115
|
+
Object.defineProperty(exports, "computeTransactionDigest", { enumerable: true, get: function () { return wasm_sync_js_7.computeTransactionDigest; } });
|
|
115
116
|
// Transaction deserialization (byte-exact inverse of the TS serializer)
|
|
116
117
|
var transaction_js_1 = require("./transaction.js");
|
|
117
118
|
Object.defineProperty(exports, "deserializeTransaction", { enumerable: true, get: function () { return transaction_js_1.deserializeTransaction; } });
|
|
118
119
|
// Verification
|
|
119
|
-
var
|
|
120
|
-
Object.defineProperty(exports, "timingSafeEqual", { enumerable: true, get: function () { return
|
|
121
|
-
Object.defineProperty(exports, "createChallenge", { enumerable: true, get: function () { return
|
|
122
|
-
Object.defineProperty(exports, "validateChallenge", { enumerable: true, get: function () { return
|
|
120
|
+
var wasm_sync_js_8 = require("./wasm-sync.js");
|
|
121
|
+
Object.defineProperty(exports, "timingSafeEqual", { enumerable: true, get: function () { return wasm_sync_js_8.timingSafeEqual; } });
|
|
122
|
+
Object.defineProperty(exports, "createChallenge", { enumerable: true, get: function () { return wasm_sync_js_8.createChallenge; } });
|
|
123
|
+
Object.defineProperty(exports, "validateChallenge", { enumerable: true, get: function () { return wasm_sync_js_8.validateChallenge; } });
|
|
123
124
|
// ---------------------------------------------------------------------------
|
|
124
125
|
// TypeScript-only modules (no crypto — keep as-is)
|
|
125
126
|
// ---------------------------------------------------------------------------
|
|
@@ -127,20 +128,22 @@ Object.defineProperty(exports, "validateChallenge", { enumerable: true, get: fun
|
|
|
127
128
|
var script_js_1 = require("./script.js");
|
|
128
129
|
Object.defineProperty(exports, "scriptFromWotsPk", { enumerable: true, get: function () { return script_js_1.scriptFromWotsPk; } });
|
|
129
130
|
// Base32 Encoding (Minima-compatible) — re-export from WASM
|
|
130
|
-
var
|
|
131
|
-
Object.defineProperty(exports, "encodeMx", { enumerable: true, get: function () { return
|
|
132
|
-
Object.defineProperty(exports, "decodeMx", { enumerable: true, get: function () { return
|
|
131
|
+
var wasm_sync_js_9 = require("./wasm-sync.js");
|
|
132
|
+
Object.defineProperty(exports, "encodeMx", { enumerable: true, get: function () { return wasm_sync_js_9.makeMxAddress; } });
|
|
133
|
+
Object.defineProperty(exports, "decodeMx", { enumerable: true, get: function () { return wasm_sync_js_9.parseMxAddress; } });
|
|
133
134
|
/** Convert an Mx (radix-32) or hex Minima address to lowercase hex. */
|
|
134
135
|
function mxToHex(address) {
|
|
135
136
|
const upper = address.startsWith('0x') || address.startsWith('0X') ? address.slice(2) : address;
|
|
136
137
|
return upper.toUpperCase().startsWith('MX')
|
|
137
|
-
? (0,
|
|
138
|
+
? (0, bytes_js_2.bytesToHex)((0, wasm_sync_js_1.parseMxAddress)(address))
|
|
138
139
|
: upper.replace(/^0x/i, '');
|
|
139
140
|
}
|
|
140
141
|
// Merkle Mountain Range (original JS — types and helpers)
|
|
141
142
|
__exportStar(require("./mmr.js"), exports);
|
|
142
143
|
// Script Types, Witness Serializer, Contract Helpers
|
|
143
144
|
__exportStar(require("./scripts/index.js"), exports);
|
|
145
|
+
var canonical_js_1 = require("./scripts/canonical.js");
|
|
146
|
+
Object.defineProperty(exports, "toNodeScript", { enumerable: true, get: function () { return canonical_js_1.toNodeScript; } });
|
|
144
147
|
// Address Derivation (original)
|
|
145
148
|
var derive_js_1 = require("./derive.js");
|
|
146
149
|
Object.defineProperty(exports, "scriptToAddress", { enumerable: true, get: function () { return derive_js_1.scriptToAddress; } });
|
|
@@ -170,6 +173,12 @@ Object.defineProperty(exports, "verifySignatureDetailed", { enumerable: true, ge
|
|
|
170
173
|
Object.defineProperty(exports, "verifyTreeSignatureDetailed", { enumerable: true, get: function () { return verify_js_1.verifyTreeSignatureDetailed; } });
|
|
171
174
|
Object.defineProperty(exports, "deriveAddressFromPublicKey", { enumerable: true, get: function () { return verify_js_1.deriveAddressFromPublicKey; } });
|
|
172
175
|
Object.defineProperty(exports, "normalizeHex", { enumerable: true, get: function () { return verify_js_1.normalizeHex; } });
|
|
176
|
+
// Deterministic address derivation (CAN-005)
|
|
177
|
+
var address_derivation_js_1 = require("./address-derivation.js");
|
|
178
|
+
Object.defineProperty(exports, "deriveDeterministicAddress", { enumerable: true, get: function () { return address_derivation_js_1.deriveDeterministicAddress; } });
|
|
179
|
+
Object.defineProperty(exports, "deriveUnifiedAddress", { enumerable: true, get: function () { return address_derivation_js_1.deriveUnifiedAddress; } });
|
|
180
|
+
Object.defineProperty(exports, "deriveAddress", { enumerable: true, get: function () { return address_derivation_js_1.deriveAddress; } });
|
|
181
|
+
Object.defineProperty(exports, "verifyDeterministicAddress", { enumerable: true, get: function () { return address_derivation_js_1.verifyDeterministicAddress; } });
|
|
173
182
|
// Streamable primitives (low-level serialization building blocks)
|
|
174
183
|
var Streamable_js_1 = require("./Streamable.js");
|
|
175
184
|
Object.defineProperty(exports, "writeMiniByte", { enumerable: true, get: function () { return Streamable_js_1.writeMiniByte; } });
|
|
@@ -224,10 +233,11 @@ Object.defineProperty(exports, "toWinternitzDigits", { enumerable: true, get: fu
|
|
|
224
233
|
Object.defineProperty(exports, "baseWWithChecksum", { enumerable: true, get: function () { return wots_js_1.baseWWithChecksum; } });
|
|
225
234
|
Object.defineProperty(exports, "wotsSignLegacy", { enumerable: true, get: function () { return wots_js_1.wotsSignLegacy; } });
|
|
226
235
|
// Canonical helpers (deterministic JSON + hashing)
|
|
227
|
-
var
|
|
228
|
-
Object.defineProperty(exports, "toHex", { enumerable: true, get: function () { return
|
|
229
|
-
Object.defineProperty(exports, "canonicalJson", { enumerable: true, get: function () { return
|
|
230
|
-
|
|
236
|
+
var canonical_js_2 = require("./canonical.js");
|
|
237
|
+
Object.defineProperty(exports, "toHex", { enumerable: true, get: function () { return canonical_js_2.toHex; } });
|
|
238
|
+
Object.defineProperty(exports, "canonicalJson", { enumerable: true, get: function () { return canonical_js_2.canonicalJson; } });
|
|
239
|
+
var canonical_hash_js_1 = require("./canonical-hash.js");
|
|
240
|
+
Object.defineProperty(exports, "hashCanonical", { enumerable: true, get: function () { return canonical_hash_js_1.hashCanonical; } });
|
|
231
241
|
// Byte/string utilities
|
|
232
242
|
var utils_js_1 = require("./utils.js");
|
|
233
243
|
Object.defineProperty(exports, "utf8ToBytes", { enumerable: true, get: function () { return utils_js_1.utf8ToBytes; } });
|
package/dist/cjs/legacy.d.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Legacy JS
|
|
2
|
+
* Legacy JS crypto kernels — **deprecated (RFC-031 P4), frozen**.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* @deprecated The pure-JS kernels are scheduled for removal (RFC-031 P5). Use
|
|
5
|
+
* the WASM surface instead:
|
|
6
|
+
* - `@totemsdk/core` / `@totemsdk/core/wasm` — synchronous WASM (bundler loader required)
|
|
7
|
+
* - `@totemsdk/core/wasm-async` — async-init WASM (portable to edge/Workers)
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* This entry stays only as a migration bridge for environments that cannot run
|
|
10
|
+
* WASM yet; it is **frozen** (no new kernels are added here) and will be deleted
|
|
11
|
+
* in a major release. Exports are `legacy`-prefixed where they collide with the
|
|
12
|
+
* WASM names (`legacyWotsSign`, …).
|
|
13
|
+
*
|
|
14
|
+
* // before
|
|
15
|
+
* import { legacyWotsSign } from '@totemsdk/core/legacy';
|
|
16
|
+
* // after
|
|
17
|
+
* import { init, wotsSign } from '@totemsdk/core/wasm-async';
|
|
18
|
+
* await init();
|
|
10
19
|
*/
|
|
11
20
|
export { F, hex, fromHex, u16be, u32be, assert32, h, prfChainSeed, toWinternitzDigits, baseWWithChecksum, derivePKdigest as legacyDerivePKdigest, wotsKeypairFromSeed as legacyWotsKeypairFromSeed, wotsSign as legacyWotsSign, wotsSignLegacy, wotsPkFromSig as legacyWotsPkFromSig, wotsVerify as legacyWotsVerify, wotsVerifyDigest as legacyWotsVerifyDigest, wotsPublicKeyFromSeed as legacyWotsPublicKeyFromSeed, type WotsKeypair, type WotsSignature, } from './wots.js';
|
|
12
21
|
export { TreeKey, TreeKeyNode, verifyTreeSignature as legacyVerifyTreeSignature, serializeTreeSignature, deserializeTreeSignature, getRootPublicKey, DEFAULT_KEYS_PER_LEVEL, DEFAULT_LEVELS, createUnifiedChildTreeKey as legacyCreateUnifiedChildTreeKey, createUnifiedChildTreeKeyAsync, createUnifiedRootTreeKey as legacyCreateUnifiedRootTreeKey, deriveUnifiedAddressPublicKey as legacyDeriveUnifiedAddressPublicKey, createPerAddressTreeKey, createPerAddressTreeKeyAsync, type KeyGenProgress, type ProgressCallback, type SignatureProof, type TreeSignature, } from './treekey.js';
|
package/dist/cjs/legacy.js
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Legacy JS
|
|
3
|
+
* Legacy JS crypto kernels — **deprecated (RFC-031 P4), frozen**.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* @deprecated The pure-JS kernels are scheduled for removal (RFC-031 P5). Use
|
|
6
|
+
* the WASM surface instead:
|
|
7
|
+
* - `@totemsdk/core` / `@totemsdk/core/wasm` — synchronous WASM (bundler loader required)
|
|
8
|
+
* - `@totemsdk/core/wasm-async` — async-init WASM (portable to edge/Workers)
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* This entry stays only as a migration bridge for environments that cannot run
|
|
11
|
+
* WASM yet; it is **frozen** (no new kernels are added here) and will be deleted
|
|
12
|
+
* in a major release. Exports are `legacy`-prefixed where they collide with the
|
|
13
|
+
* WASM names (`legacyWotsSign`, …).
|
|
14
|
+
*
|
|
15
|
+
* // before
|
|
16
|
+
* import { legacyWotsSign } from '@totemsdk/core/legacy';
|
|
17
|
+
* // after
|
|
18
|
+
* import { init, wotsSign } from '@totemsdk/core/wasm-async';
|
|
19
|
+
* await init();
|
|
11
20
|
*/
|
|
12
21
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
22
|
if (k2 === undefined) k2 = k;
|
package/dist/cjs/mmr.d.ts
CHANGED
|
@@ -16,6 +16,28 @@ export type Bytes = Uint8Array;
|
|
|
16
16
|
export declare function mmrLeafExact(script: string): Bytes;
|
|
17
17
|
/** In a single-leaf MMR the root equals the leaf commitment. */
|
|
18
18
|
export declare function mmrRootFromSingleLeaf(script: string): Bytes;
|
|
19
|
+
/**
|
|
20
|
+
* Build the serialized Minima `ScriptProof` bytes for a single-leaf MMR.
|
|
21
|
+
*
|
|
22
|
+
* Mirrors the node's `ScriptProof(const std::string& zScript)` constructor
|
|
23
|
+
* (org/minima/objects/script_proof.cpp): the script is added as the sole leaf
|
|
24
|
+
* of a fresh MMR with sum value ZERO, so the proof chain is empty and the
|
|
25
|
+
* resulting address is the leaf commitment itself:
|
|
26
|
+
*
|
|
27
|
+
* address = sha3( MiniNumber.ZERO || MiniString(script) || MiniNumber.ZERO )
|
|
28
|
+
* = mmrLeafExact(script)
|
|
29
|
+
*
|
|
30
|
+
* This is exactly how the node derives `Address(script)`, so a witness carrying
|
|
31
|
+
* this proof satisfies `Witness::getScript(input.getAddress())` for every input
|
|
32
|
+
* paying to that script. Without it the node rejects the TxPoW with
|
|
33
|
+
* "Script Missing from TxPoW for address <addr>".
|
|
34
|
+
*
|
|
35
|
+
* Wire format (`ScriptProof::writeDataStream`):
|
|
36
|
+
* MiniString(script) || MMRProof(blockTime = 0, chunks = [])
|
|
37
|
+
*
|
|
38
|
+
* @param script - The Minima (KISSVM) script whose address the proof attests.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildScriptProof(script: string): Bytes;
|
|
19
41
|
/**
|
|
20
42
|
* MMRData structure matching Minima's MMRData.java
|
|
21
43
|
* Contains hash and value (for sum tree functionality)
|
package/dist/cjs/mmr.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.deserializeMMRProof = exports.MMRTree = exports.serializeRealMMRProof =
|
|
|
4
4
|
exports.serializeMMRProof = serializeMMRProof;
|
|
5
5
|
exports.mmrLeafExact = mmrLeafExact;
|
|
6
6
|
exports.mmrRootFromSingleLeaf = mmrRootFromSingleLeaf;
|
|
7
|
+
exports.buildScriptProof = buildScriptProof;
|
|
7
8
|
exports.createMMRDataLeafNode = createMMRDataLeafNode;
|
|
8
9
|
exports.createMMRDataParentNode = createMMRDataParentNode;
|
|
9
10
|
exports.calculateProofRoot = calculateProofRoot;
|
|
@@ -15,6 +16,9 @@ const wasm_sync_js_1 = require("./wasm-sync.js");
|
|
|
15
16
|
const javaStreamables_js_1 = require("./javaStreamables.js");
|
|
16
17
|
// Import canonical wire serialization from Streamable.ts (single source of truth)
|
|
17
18
|
const Streamable_js_1 = require("./Streamable.js");
|
|
19
|
+
// Canonicalise to the exact script the node will receive, so the proof's
|
|
20
|
+
// computed address matches `computeScriptAddress` (which canonicalises too).
|
|
21
|
+
const canonical_js_1 = require("./scripts/canonical.js");
|
|
18
22
|
// Re-export for API compatibility (existing code imports from mmr.ts)
|
|
19
23
|
// Using a wrapper function for better compatibility with dynamic imports
|
|
20
24
|
function serializeMMRProof(proof, blockTime = 0n) {
|
|
@@ -80,6 +84,35 @@ function mmrLeafExact(script) {
|
|
|
80
84
|
function mmrRootFromSingleLeaf(script) {
|
|
81
85
|
return mmrLeafExact(script);
|
|
82
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Build the serialized Minima `ScriptProof` bytes for a single-leaf MMR.
|
|
89
|
+
*
|
|
90
|
+
* Mirrors the node's `ScriptProof(const std::string& zScript)` constructor
|
|
91
|
+
* (org/minima/objects/script_proof.cpp): the script is added as the sole leaf
|
|
92
|
+
* of a fresh MMR with sum value ZERO, so the proof chain is empty and the
|
|
93
|
+
* resulting address is the leaf commitment itself:
|
|
94
|
+
*
|
|
95
|
+
* address = sha3( MiniNumber.ZERO || MiniString(script) || MiniNumber.ZERO )
|
|
96
|
+
* = mmrLeafExact(script)
|
|
97
|
+
*
|
|
98
|
+
* This is exactly how the node derives `Address(script)`, so a witness carrying
|
|
99
|
+
* this proof satisfies `Witness::getScript(input.getAddress())` for every input
|
|
100
|
+
* paying to that script. Without it the node rejects the TxPoW with
|
|
101
|
+
* "Script Missing from TxPoW for address <addr>".
|
|
102
|
+
*
|
|
103
|
+
* Wire format (`ScriptProof::writeDataStream`):
|
|
104
|
+
* MiniString(script) || MMRProof(blockTime = 0, chunks = [])
|
|
105
|
+
*
|
|
106
|
+
* @param script - The Minima (KISSVM) script whose address the proof attests.
|
|
107
|
+
*/
|
|
108
|
+
function buildScriptProof(script) {
|
|
109
|
+
// The node derives the proof's address as
|
|
110
|
+
// sha3( MiniNumber.ZERO || MiniString(script) || MiniNumber.ZERO )
|
|
111
|
+
// so the script bytes here must be exactly the canonical script whose address
|
|
112
|
+
// was used for the coin (see computeScriptAddress).
|
|
113
|
+
const canonical = (0, canonical_js_1.toNodeScript)(script);
|
|
114
|
+
return concat((0, Streamable_js_1.writeMiniString)(canonical), serializeMMRProof({ chunks: [] }, 0n));
|
|
115
|
+
}
|
|
83
116
|
/**
|
|
84
117
|
* Create MMRData leaf node matching Minima's MMRData.CreateMMRDataLeafNode
|
|
85
118
|
*
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `toNodeScript` — canonicalize a KISSVM script to the syntax the Minima **node**
|
|
3
|
+
* tokenizer accepts (RFC-048 §3.1 L4 finding; audit
|
|
4
|
+
* `docs/audits/kissvm-node-validity-l4-2026-10.md`).
|
|
5
|
+
*
|
|
6
|
+
* The node tokenizer requires:
|
|
7
|
+
* - user variable names `^[a-z]+$` (lowercase letters only — no digits/underscores/uppercase),
|
|
8
|
+
* - hex literals `^0x[0-9a-fA-F]+$` (lowercase `0x` prefix),
|
|
9
|
+
* - arithmetic via the `+` / `-` operators (`ADD`/`SUB` are not node functions).
|
|
10
|
+
*
|
|
11
|
+
* This is a token-level rewrite: commands, functions, operators, globals (`@…`), hex
|
|
12
|
+
* literals, numbers and `[…]` string literals are preserved; only **user identifiers**
|
|
13
|
+
* are rewritten to lowercase letters (with deterministic de-collision), `0X`→`0x`, and
|
|
14
|
+
* `ADD`/`SUB`→`+`/`-`. It is idempotent.
|
|
15
|
+
*
|
|
16
|
+
* Semantics are unchanged: the SDK evaluators normalize `+`→ADD and `-`→SUB (and vice
|
|
17
|
+
* versa), so a canonical script behaves identically to its source.
|
|
18
|
+
*/
|
|
19
|
+
/** Canonicalize a KISSVM script to node-accepted syntax. Idempotent. */
|
|
20
|
+
export declare function toNodeScript(script: string): string;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `toNodeScript` — canonicalize a KISSVM script to the syntax the Minima **node**
|
|
4
|
+
* tokenizer accepts (RFC-048 §3.1 L4 finding; audit
|
|
5
|
+
* `docs/audits/kissvm-node-validity-l4-2026-10.md`).
|
|
6
|
+
*
|
|
7
|
+
* The node tokenizer requires:
|
|
8
|
+
* - user variable names `^[a-z]+$` (lowercase letters only — no digits/underscores/uppercase),
|
|
9
|
+
* - hex literals `^0x[0-9a-fA-F]+$` (lowercase `0x` prefix),
|
|
10
|
+
* - arithmetic via the `+` / `-` operators (`ADD`/`SUB` are not node functions).
|
|
11
|
+
*
|
|
12
|
+
* This is a token-level rewrite: commands, functions, operators, globals (`@…`), hex
|
|
13
|
+
* literals, numbers and `[…]` string literals are preserved; only **user identifiers**
|
|
14
|
+
* are rewritten to lowercase letters (with deterministic de-collision), `0X`→`0x`, and
|
|
15
|
+
* `ADD`/`SUB`→`+`/`-`. It is idempotent.
|
|
16
|
+
*
|
|
17
|
+
* Semantics are unchanged: the SDK evaluators normalize `+`→ADD and `-`→SUB (and vice
|
|
18
|
+
* versa), so a canonical script behaves identically to its source.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.toNodeScript = toNodeScript;
|
|
22
|
+
const KEYWORDS = new Set([
|
|
23
|
+
'LET', 'IF', 'THEN', 'ELSE', 'ELSEIF', 'ENDIF', 'RETURN', 'ASSERT', 'EXEC', 'MAST',
|
|
24
|
+
'WHILE', 'DO', 'ENDWHILE', 'FOR', 'TO', 'BY', 'ENDFOR', 'FOREACH', 'IN', 'SWITCH',
|
|
25
|
+
'CASE', 'DEFAULT', 'ENDSWITCH', 'FUNC', 'ENDFUNC', 'TRUE', 'FALSE', 'STORE', 'WITH', 'FUNCTION', 'RETURN',
|
|
26
|
+
]);
|
|
27
|
+
// Word operators kept as-is (ADD/SUB are handled separately → +/−).
|
|
28
|
+
const OPS = new Set([
|
|
29
|
+
'GT', 'LT', 'EQ', 'GTE', 'LTE', 'NEQ', 'AND', 'OR', 'XOR', 'NAND', 'NOR', 'NXOR',
|
|
30
|
+
'NOT', 'NEG', 'MUL', 'DIV', 'MOD', 'LSHIFT', 'RSHIFT', 'BITAND', 'BITOR', 'BITXOR', 'BITNOT',
|
|
31
|
+
]);
|
|
32
|
+
const FUNCTIONS = new Set([
|
|
33
|
+
'SHA3', 'SHA2', 'HASH', 'PROOF', 'SIGNEDBY', 'MULTISIG', 'CHECKSIG', 'VERIFYOUT', 'VERIFYIN',
|
|
34
|
+
'GETOUTADDR', 'GETOUTAMT', 'GETOUTTOK', 'GETOUTKEEPSTATE', 'GETINADDR', 'GETINAMT', 'GETINID',
|
|
35
|
+
'GETINTOK', 'STATE', 'PREVSTATE', 'SAMESTATE', 'SAMECOINS', 'COINAGE', 'COINDATA', 'NUMBER',
|
|
36
|
+
'HEX', 'STRING', 'ASCII', 'UTF8', 'BOOL', 'CONCAT', 'LEN', 'REV', 'SUBSET', 'SETLEN',
|
|
37
|
+
'SUBSTR', 'REPLACE', 'REPLACEFIRST', 'OVERWRITE', 'ABS', 'CEIL', 'FLOOR', 'MAX', 'MIN',
|
|
38
|
+
'DEC', 'INC', 'SIGDIG', 'POW', 'SQRT', 'BITSET', 'BITGET', 'BITCOUNT', 'ADDRESS', 'EXISTS',
|
|
39
|
+
'GET', 'SUMINPUTS', 'SUMOUTPUTS', 'CHECKSIG',
|
|
40
|
+
]);
|
|
41
|
+
function classify(id) {
|
|
42
|
+
const up = id.toUpperCase();
|
|
43
|
+
if (up === 'ADD')
|
|
44
|
+
return { kind: 'keep', out: '+' };
|
|
45
|
+
if (up === 'SUB')
|
|
46
|
+
return { kind: 'keep', out: '-' };
|
|
47
|
+
if (KEYWORDS.has(up) || OPS.has(up) || FUNCTIONS.has(up))
|
|
48
|
+
return { kind: 'keep', out: up };
|
|
49
|
+
return { kind: 'var' };
|
|
50
|
+
}
|
|
51
|
+
/** a, b, …, z, aa, ab, … */
|
|
52
|
+
function letters(n) {
|
|
53
|
+
let s = '';
|
|
54
|
+
n += 1;
|
|
55
|
+
while (n > 0) {
|
|
56
|
+
const r = (n - 1) % 26;
|
|
57
|
+
s = String.fromCharCode(97 + r) + s;
|
|
58
|
+
n = Math.floor((n - 1) / 26);
|
|
59
|
+
}
|
|
60
|
+
return s;
|
|
61
|
+
}
|
|
62
|
+
const TOKEN = /(\[[^\]]*\]|0[xX][0-9a-fA-F]+|@[A-Za-z][A-Za-z0-9]*|[A-Za-z_][A-Za-z0-9_]*)/g;
|
|
63
|
+
/** Canonicalize a KISSVM script to node-accepted syntax. Idempotent. */
|
|
64
|
+
function toNodeScript(script) {
|
|
65
|
+
// The node tokenizer has no comment syntax; strip `//` line comments.
|
|
66
|
+
script = script.replace(/\/\/[^\n]*/g, '');
|
|
67
|
+
const varMap = new Map();
|
|
68
|
+
const used = new Set();
|
|
69
|
+
// First pass: assign canonical names to user variables (in first-occurrence order).
|
|
70
|
+
let m;
|
|
71
|
+
const re1 = new RegExp(TOKEN.source, 'g');
|
|
72
|
+
while ((m = re1.exec(script))) {
|
|
73
|
+
const tok = m[0];
|
|
74
|
+
if (tok[0] === '[' || tok.startsWith('0x') || tok.startsWith('0X') || tok[0] === '@')
|
|
75
|
+
continue;
|
|
76
|
+
if (classify(tok).kind !== 'var' || varMap.has(tok))
|
|
77
|
+
continue;
|
|
78
|
+
const base = tok.toLowerCase().replace(/[^a-z]/g, '') || 'v';
|
|
79
|
+
let cand = base;
|
|
80
|
+
let i = 0;
|
|
81
|
+
while (used.has(cand))
|
|
82
|
+
cand = base + letters(i++);
|
|
83
|
+
used.add(cand);
|
|
84
|
+
varMap.set(tok, cand);
|
|
85
|
+
}
|
|
86
|
+
// Second pass: rewrite.
|
|
87
|
+
return script.replace(TOKEN, (tok) => {
|
|
88
|
+
if (tok[0] === '[')
|
|
89
|
+
return tok;
|
|
90
|
+
if (tok.startsWith('0x') || tok.startsWith('0X'))
|
|
91
|
+
return '0x' + tok.slice(2);
|
|
92
|
+
if (tok[0] === '@')
|
|
93
|
+
return '@' + tok.slice(1).toUpperCase();
|
|
94
|
+
const c = classify(tok);
|
|
95
|
+
if (c.kind === 'keep')
|
|
96
|
+
return c.out;
|
|
97
|
+
return varMap.get(tok) ?? tok;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -17,9 +17,9 @@
|
|
|
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
19
|
const wasm_sync_js_1 = require("../wasm-sync.js");
|
|
20
|
-
const
|
|
20
|
+
const sha256_js_1 = require("@noble/hashes/sha256.js");
|
|
21
21
|
function sha256(data) {
|
|
22
|
-
return
|
|
22
|
+
return (0, sha256_js_1.sha256)(data);
|
|
23
23
|
}
|
|
24
24
|
const types_js_1 = require("./types.js");
|
|
25
25
|
function kissHex(hex) {
|
|
@@ -83,7 +83,7 @@ class HTLCHelper {
|
|
|
83
83
|
* Generate a random preimage and its hash.
|
|
84
84
|
*/
|
|
85
85
|
static generateSecret() {
|
|
86
|
-
const preimageBytes = (
|
|
86
|
+
const preimageBytes = globalThis.crypto.getRandomValues(new Uint8Array(32));
|
|
87
87
|
const preimage = bytesToHex(preimageBytes);
|
|
88
88
|
const hashBytes = (0, wasm_sync_js_1.sha3_256)(preimageBytes);
|
|
89
89
|
const hash = bytesToHex(hashBytes);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
2
|
export * from './dapp-types.js';
|
|
3
|
-
export { encodeMiniNumber, encodeMiniData, encodeMiniString, serializeMMRProofChunk, serializeScriptProofWithProof, STATETYPE_HEX, STATETYPE_NUMBER, STATETYPE_STRING, STATETYPE_BOOL, encodeStateValue, serializeStateVariables, buildScriptProofFromDescriptor, deduplicateScriptDescriptors, serializeExtraScripts, aggregateSignatures, validateExternalSignature, computeScriptAddress, } from './witness-serializer.js';
|
|
3
|
+
export { encodeMiniNumber, encodeMiniData, encodeMiniString, serializeMMRProofChunk, serializeScriptProofWithProof, STATETYPE_HEX, STATETYPE_NUMBER, STATETYPE_STRING, STATETYPE_BOOL, encodeStateValue, serializeStateVariables, buildScriptProofFromDescriptor, deduplicateScriptDescriptors, serializeExtraScripts, aggregateSignatures, validateExternalSignature, computeScriptAddress, wotsAddressData, } from './witness-serializer.js';
|
|
4
4
|
export * from './contract-helpers.js';
|
|
5
|
+
export { toNodeScript } from "./canonical.js";
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.computeScriptAddress = exports.validateExternalSignature = exports.aggregateSignatures = exports.serializeExtraScripts = exports.deduplicateScriptDescriptors = exports.buildScriptProofFromDescriptor = exports.serializeStateVariables = exports.encodeStateValue = exports.STATETYPE_BOOL = exports.STATETYPE_STRING = exports.STATETYPE_NUMBER = exports.STATETYPE_HEX = exports.serializeScriptProofWithProof = exports.serializeMMRProofChunk = exports.encodeMiniString = exports.encodeMiniData = exports.encodeMiniNumber = void 0;
|
|
17
|
+
exports.toNodeScript = exports.wotsAddressData = exports.computeScriptAddress = exports.validateExternalSignature = exports.aggregateSignatures = exports.serializeExtraScripts = exports.deduplicateScriptDescriptors = exports.buildScriptProofFromDescriptor = exports.serializeStateVariables = exports.encodeStateValue = exports.STATETYPE_BOOL = exports.STATETYPE_STRING = exports.STATETYPE_NUMBER = exports.STATETYPE_HEX = exports.serializeScriptProofWithProof = exports.serializeMMRProofChunk = exports.encodeMiniString = exports.encodeMiniData = exports.encodeMiniNumber = void 0;
|
|
18
18
|
__exportStar(require("./types.js"), exports);
|
|
19
19
|
__exportStar(require("./dapp-types.js"), exports);
|
|
20
20
|
var witness_serializer_js_1 = require("./witness-serializer.js");
|
|
@@ -35,4 +35,7 @@ Object.defineProperty(exports, "serializeExtraScripts", { enumerable: true, get:
|
|
|
35
35
|
Object.defineProperty(exports, "aggregateSignatures", { enumerable: true, get: function () { return witness_serializer_js_1.aggregateSignatures; } });
|
|
36
36
|
Object.defineProperty(exports, "validateExternalSignature", { enumerable: true, get: function () { return witness_serializer_js_1.validateExternalSignature; } });
|
|
37
37
|
Object.defineProperty(exports, "computeScriptAddress", { enumerable: true, get: function () { return witness_serializer_js_1.computeScriptAddress; } });
|
|
38
|
+
Object.defineProperty(exports, "wotsAddressData", { enumerable: true, get: function () { return witness_serializer_js_1.wotsAddressData; } });
|
|
38
39
|
__exportStar(require("./contract-helpers.js"), exports);
|
|
40
|
+
var canonical_js_1 = require("./canonical.js");
|
|
41
|
+
Object.defineProperty(exports, "toNodeScript", { enumerable: true, get: function () { return canonical_js_1.toNodeScript; } });
|
|
@@ -25,5 +25,24 @@ export declare function aggregateSignatures(totemSignature: {
|
|
|
25
25
|
signature: Uint8Array;
|
|
26
26
|
}, externalSignatures: ExternalSignature[], transactionDigest: Uint8Array): Uint8Array[];
|
|
27
27
|
export declare function validateExternalSignature(signature: ExternalSignature, transactionDigest: Uint8Array): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Derive a Minima script address exactly as the node does
|
|
30
|
+
* (`Address::Address(script)` / `ScriptProof::calculateAddress`):
|
|
31
|
+
*
|
|
32
|
+
* address = sha3( MiniNumber.ZERO || MiniString(script) || MiniNumber.ZERO )
|
|
33
|
+
*
|
|
34
|
+
* The script is first canonicalised (`toNodeScript`) so the address is over the
|
|
35
|
+
* same bytes the node will execute and that `buildScriptProof` attests. The
|
|
36
|
+
* previous implementation hashed `sha3(upper(script))`, which is not a Minima
|
|
37
|
+
* script address — coins sent to it could never be spent by that script
|
|
38
|
+
* ("Script Missing from TxPoW for address …").
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Address data (hex) of a WOTS public-key digest's single-key script
|
|
42
|
+
* (`RETURN SIGNEDBY(0x<pk>)`). This is the value a `VERIFYOUT` compares against
|
|
43
|
+
* (the node compares the output coin's *address data*), distinct from the WOTS
|
|
44
|
+
* public key used by `SIGNEDBY`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function wotsAddressData(publicKeyDigest: string): string;
|
|
28
47
|
export declare function computeScriptAddress(script: string): string;
|
|
29
48
|
export { concat };
|
|
@@ -15,9 +15,10 @@ exports.deduplicateScriptDescriptors = deduplicateScriptDescriptors;
|
|
|
15
15
|
exports.serializeExtraScripts = serializeExtraScripts;
|
|
16
16
|
exports.aggregateSignatures = aggregateSignatures;
|
|
17
17
|
exports.validateExternalSignature = validateExternalSignature;
|
|
18
|
+
exports.wotsAddressData = wotsAddressData;
|
|
18
19
|
exports.computeScriptAddress = computeScriptAddress;
|
|
19
20
|
exports.concat = concat;
|
|
20
|
-
const
|
|
21
|
+
const canonical_js_1 = require("./canonical.js");
|
|
21
22
|
const wots_js_1 = require("../wots.js");
|
|
22
23
|
const mmr_js_1 = require("../mmr.js");
|
|
23
24
|
const minima32_js_1 = require("../minima32.js");
|
|
@@ -321,9 +322,28 @@ function validateExternalSignature(signature, transactionDigest) {
|
|
|
321
322
|
return false;
|
|
322
323
|
}
|
|
323
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Derive a Minima script address exactly as the node does
|
|
327
|
+
* (`Address::Address(script)` / `ScriptProof::calculateAddress`):
|
|
328
|
+
*
|
|
329
|
+
* address = sha3( MiniNumber.ZERO || MiniString(script) || MiniNumber.ZERO )
|
|
330
|
+
*
|
|
331
|
+
* The script is first canonicalised (`toNodeScript`) so the address is over the
|
|
332
|
+
* same bytes the node will execute and that `buildScriptProof` attests. The
|
|
333
|
+
* previous implementation hashed `sha3(upper(script))`, which is not a Minima
|
|
334
|
+
* script address — coins sent to it could never be spent by that script
|
|
335
|
+
* ("Script Missing from TxPoW for address …").
|
|
336
|
+
*/
|
|
337
|
+
/**
|
|
338
|
+
* Address data (hex) of a WOTS public-key digest's single-key script
|
|
339
|
+
* (`RETURN SIGNEDBY(0x<pk>)`). This is the value a `VERIFYOUT` compares against
|
|
340
|
+
* (the node compares the output coin's *address data*), distinct from the WOTS
|
|
341
|
+
* public key used by `SIGNEDBY`.
|
|
342
|
+
*/
|
|
343
|
+
function wotsAddressData(publicKeyDigest) {
|
|
344
|
+
const raw = publicKeyDigest.replace(/^0x/i, '').toUpperCase();
|
|
345
|
+
return computeScriptAddress(`RETURN SIGNEDBY(0x${raw})`);
|
|
346
|
+
}
|
|
324
347
|
function computeScriptAddress(script) {
|
|
325
|
-
|
|
326
|
-
const scriptBytes = new TextEncoder().encode(cleanScript);
|
|
327
|
-
const hashBytes = (0, wasm_sync_js_1.sha3_256)(scriptBytes);
|
|
328
|
-
return bytesToHex(hashBytes);
|
|
348
|
+
return bytesToHex((0, mmr_js_1.mmrRootFromSingleLeaf)((0, canonical_js_1.toNodeScript)(script)));
|
|
329
349
|
}
|
package/dist/cjs/wasm-sync.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* import { wotsSign, sha3_256 } from '@totemsdk/core/wasm';
|
|
9
9
|
* const sig = wotsSign(seed, 0, message); // synchronous!
|
|
10
10
|
*/
|
|
11
|
-
import { bytes_to_hex_wasm, clean_seed_phrase_wasm, compute_transaction_digest_wasm, concat_bytes_wasm,
|
|
11
|
+
import { bytes_to_hex_wasm, clean_seed_phrase_wasm, compute_transaction_digest_wasm, concat_bytes_wasm, create_unified_child_tree_key_wasm, create_unified_root_tree_key_wasm, derive_chain_seed_wasm, derive_full_public_key_batch_wasm, derive_full_public_key_wasm, derive_per_address_seed_wasm, derive_pk_digest_batch_wasm, derive_pk_digest_wasm, derive_root_priv_seed_wasm, derive_unified_address_public_key_wasm, expand_private_key_wasm, generate_mnemonic_wasm, get_params, hash_chain_wasm, hex_to_bytes_wasm, make_mx_address_wasm, mine_txpow_chunk_wasm, mine_txpow_wasm, mmr_root_from_public_keys_wasm, parse_mx_address_wasm, phrase_to_seed_wasm, precompute_transaction_coin_id_wasm, serialize_transaction_wasm, sha3_256_wasm, timing_safe_equal_wasm, validate_phrase_wasm, verify_mmr_proof_wasm, verify_tree_signature_wasm, wasm_tree_key_free, wasm_tree_key_get_max_uses, wasm_tree_key_get_public_key, wasm_tree_key_get_uses, wasm_tree_key_new, wasm_tree_key_set_uses, wasm_tree_key_sign, wots_pk_from_sig_wasm, wots_sign_batch_wasm, wots_sign_wasm, wots_verify_digest_wasm, wots_verify_wasm, write_mini_data_wasm, write_mini_string_wasm } from '@totemsdk/core-wasm';
|
|
12
12
|
export declare const bytesToHex: typeof bytes_to_hex_wasm;
|
|
13
13
|
export declare const hexToBytes: typeof hex_to_bytes_wasm;
|
|
14
14
|
export declare const concatBytes: typeof concat_bytes_wasm;
|
|
@@ -41,8 +41,8 @@ export declare const computeTransactionDigest: typeof compute_transaction_digest
|
|
|
41
41
|
export declare const precomputeTransactionCoinID: typeof precompute_transaction_coin_id_wasm;
|
|
42
42
|
export declare const verifyTreeSignature: typeof verify_tree_signature_wasm;
|
|
43
43
|
export declare const timingSafeEqual: typeof timing_safe_equal_wasm;
|
|
44
|
-
export declare
|
|
45
|
-
export declare
|
|
44
|
+
export declare function createChallenge(domain: string, statement: string): string;
|
|
45
|
+
export declare function validateChallenge(challengeJson: string, domain: string): boolean;
|
|
46
46
|
export declare function writeMiniNumber(value: bigint, scale?: number): Uint8Array;
|
|
47
47
|
export declare const writeMiniData: typeof write_mini_data_wasm;
|
|
48
48
|
export declare const writeMiniString: typeof write_mini_string_wasm;
|