@totemsdk/core 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bip39.js CHANGED
@@ -11,7 +11,7 @@
11
11
  * - cleanSeedPhrase(): Normalizes input with prefix matching
12
12
  * - convertStringToSeed(): Hashes phrase bytes with SHA3-256
13
13
  */
14
- import { sha3_256 } from '@noble/hashes/sha3';
14
+ import { sha3_256 } from '@noble/hashes/sha3.js';
15
15
  /**
16
16
  * Official BIP39 English word list (2048 words)
17
17
  * From https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt
@@ -0,0 +1,16 @@
1
+ export declare function signAndFinalize({ apiUrl, apiKey, txId, rootPublicKey, to, amount, tokenId, }: {
2
+ apiUrl: string;
3
+ apiKey: string;
4
+ txId: string;
5
+ rootPublicKey: string;
6
+ to: string;
7
+ amount: string;
8
+ tokenId?: string;
9
+ }): Promise<{
10
+ prep: import("./lease-client.js").PrepareResp;
11
+ fin: {
12
+ status: number;
13
+ body: string;
14
+ };
15
+ flatIndex: number;
16
+ }>;
@@ -0,0 +1,20 @@
1
+ import { prepareLease, finalizeLease, flatIndexFromLanes } from './lease-client.js';
2
+ // import { wotsSign } from './wots'; // your existing signer
3
+ // import { hexToBytes, bytesToHex } from '../utils'; // wherever you keep these
4
+ export async function signAndFinalize({ apiUrl, apiKey, txId, rootPublicKey, to, amount, tokenId = "0x00",
5
+ // digestTxBytes, masterSeed, // <- supply when you wire your real signing
6
+ }) {
7
+ // 1) PREPARE
8
+ const prep = await prepareLease(apiUrl, apiKey, { txId, rootPublicKey, to, amount, tokenId });
9
+ // 2) Map lanes -> flat index for WOTS
10
+ const { l1, l2, l3 } = prep.lease;
11
+ const flatIndex = flatIndexFromLanes(l1, l2, l3);
12
+ // 3) Produce signature with your existing WOTS(w=8)
13
+ // const sig = wotsSign(digestTxBytes, masterSeed, flatIndex);
14
+ // const signedHex = bytesToHex(serializeSignature(sig));
15
+ // For now we just show where it goes:
16
+ const signedHex = "0x<fill-with-real-signature>";
17
+ // 4) FINALIZE
18
+ const fin = await finalizeLease(apiUrl, apiKey, prep.leaseToken, signedHex);
19
+ return { prep, fin, flatIndex };
20
+ }
@@ -12,7 +12,7 @@
12
12
  * NOTE: This module provides number-based wrappers for backward compatibility.
13
13
  * The canonical implementations are in Streamable.ts which uses bigint for precision.
14
14
  */
15
- import { sha3_256 } from '@noble/hashes/sha3';
15
+ import { sha3_256 } from '@noble/hashes/sha3.js';
16
16
  import { writeMiniNumber as streamableWriteMiniNumber, writeMiniData as streamableWriteMiniData, writeHashToStream as streamableWriteHashToStream, bigIntToByteArray } from './Streamable.js';
17
17
  /**
18
18
  * Serialize a number in MiniNumber format (Java compatible)
package/dist/minima32.js CHANGED
@@ -39,7 +39,7 @@ export function decodeMxRadix32Frame(mx) {
39
39
  }
40
40
  return bigIntToBytes(x);
41
41
  }
42
- import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3';
42
+ import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3.js';
43
43
  /** Encode raw 32 bytes to Mx address with frame and checksum */
44
44
  export function makeMxAddress(root32) {
45
45
  if (root32.length !== 32) {
package/dist/mmr.d.ts CHANGED
@@ -151,6 +151,7 @@ export declare function verifyMMRProof(leafPubkey: Bytes, proof: MMRProof, expec
151
151
  export declare function parseMMRProofFromHex(data: Bytes): {
152
152
  proof: MMRProof;
153
153
  blockTime: bigint;
154
+ bytesRead: number;
154
155
  };
155
156
  /** @deprecated Use parseMMRProofFromHex */
156
157
  export declare const deserializeMMRProof: typeof parseMMRProofFromHex;
package/dist/mmr.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // packages/totem-sdk/packages/core/src/mmr.ts
2
2
  // Full MMR implementation matching Minima's MMR.java, MMRData.java, and TreeKeyNode.java
3
- import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3';
3
+ import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3.js';
4
4
  import { serializeMiniNumber, serializeMiniData, javaHashAllObjects } from "./javaStreamables.js";
5
5
  // Import canonical wire serialization from Streamable.ts (single source of truth)
6
6
  import { writeMMRProof } from "./Streamable.js";
@@ -315,7 +315,7 @@ export function parseMMRProofFromHex(data) {
315
315
  offset += cvRead;
316
316
  chunks.push({ isLeft, mmrData: { data: hashData, value: chunkValue } });
317
317
  }
318
- return { proof: { chunks }, blockTime };
318
+ return { proof: { chunks }, blockTime, bytesRead: offset };
319
319
  }
320
320
  /**
321
321
  * Read a MiniNumber from bytes at the given offset
@@ -13,9 +13,9 @@
13
13
  * Each helper validates inputs and builds the appropriate ScriptDescriptor
14
14
  * for use with the EnhancedTransactionBuilder.
15
15
  */
16
- import { sha3_256 } from '@noble/hashes/sha3';
17
- import { sha256 } from '@noble/hashes/sha256';
18
- import { randomBytes } from '@noble/hashes/utils';
16
+ import { sha3_256 } from '@noble/hashes/sha3.js';
17
+ import { sha256 } from '@noble/hashes/sha2.js';
18
+ import { randomBytes } from '@noble/hashes/utils.js';
19
19
  import { createTimelockDescriptor, createHTLCDescriptor, createMASTDescriptor, createExchangeDescriptor, createFlashCashDescriptor, createSlowCashDescriptor } from './types.js';
20
20
  function kissHex(hex) {
21
21
  const raw = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
@@ -1,4 +1,4 @@
1
- import { sha3_256 } from '@noble/hashes/sha3';
1
+ import { sha3_256 } from '@noble/hashes/sha3.js';
2
2
  import { serializeMMRProof } from '../mmr.js';
3
3
  import { mxToHex } from '../minima32.js';
4
4
  function hexToBytes(hex) {
@@ -10,7 +10,7 @@
10
10
  * precomputeTransactionCoinID() to set output coin IDs. Without this, the signed
11
11
  * digest won't match what the Minima node verifies, causing allsignaturesvalid=false.
12
12
  */
13
- import { sha3_256 } from '@noble/hashes/sha3';
13
+ import { sha3_256 } from '@noble/hashes/sha3.js';
14
14
  import { writeMiniNumber, writeMiniData, writeHashToStream, writeMiniByte, writeMMREntryNumber, concat, hexToBytes, } from './Streamable.js';
15
15
  const ZERO_TXPOWID = new Uint8Array([0x00]);
16
16
  const STATETYPE_HEX = 1;
package/dist/treekey.js CHANGED
@@ -681,12 +681,8 @@ export function deserializeTreeSignature(data) {
681
681
  offset += 4;
682
682
  const signature = data.slice(offset, offset + sigLen);
683
683
  offset += sigLen;
684
- // MMR proof - new format returns { proof, blockTime }
685
- const { proof: mmrProof } = parseMMRProofFromHex(data.slice(offset));
686
- // Calculate how many bytes the MMR proof consumed
687
- // Format: blockTime (MiniNumber: 3 bytes for 0) + length (MiniNumber: 3 bytes for count)
688
- // + each chunk (1 byte isLeft + 32 bytes hash + 3 bytes value MiniNumber)
689
- const mmrProofLen = 3 + 3 + (mmrProof.chunks.length * (1 + 32 + 3));
684
+ // MMR proof - returns { proof, blockTime, bytesRead }
685
+ const { proof: mmrProof, bytesRead: mmrProofLen } = parseMMRProofFromHex(data.slice(offset));
690
686
  offset += mmrProofLen;
691
687
  proofs.push({ leafPubkey, signature, mmrProof });
692
688
  }
package/dist/verify.js CHANGED
@@ -1,4 +1,4 @@
1
- import { sha3_256 } from '@noble/hashes/sha3';
1
+ import { sha3_256 } from '@noble/hashes/sha3.js';
2
2
  import { deserializeTreeSignature } from './treekey.js';
3
3
  import { scriptToAddress } from './derive.js';
4
4
  import { scriptFromWotsPk } from './script.js';
package/dist/wots.js CHANGED
@@ -12,7 +12,7 @@
12
12
  *
13
13
  * Source: org.bouncycastle.pqc.crypto.gmss.util.{WinternitzOTSignature, WinternitzOTSVerify, GMSSRandom}
14
14
  */
15
- import { sha3_256 } from '@noble/hashes/sha3';
15
+ import { sha3_256 } from '@noble/hashes/sha3.js';
16
16
  import { getParamSet } from "./params.js";
17
17
  import { deriveChainSeedJava } from "./javaStreamables.js";
18
18
  import { NoopLogger } from "./adapters/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totemsdk/core",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Core cryptographic primitives for Totem SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,6 +28,12 @@
28
28
  },
29
29
  "./test-vectors.json": "./test-vectors.json"
30
30
  },
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "clean": "rm -rf dist",
34
+ "test": "jest --passWithNoTests",
35
+ "gen:pkdigest": "node scripts/gen_wots_pkdigest_vectors.cjs"
36
+ },
31
37
  "files": [
32
38
  "dist",
33
39
  "src",
@@ -56,11 +62,5 @@
56
62
  "publishConfig": {
57
63
  "access": "public"
58
64
  },
59
- "license": "MIT",
60
- "scripts": {
61
- "build": "tsc",
62
- "clean": "rm -rf dist",
63
- "test": "jest --passWithNoTests",
64
- "gen:pkdigest": "node scripts/gen_wots_pkdigest_vectors.cjs"
65
- }
66
- }
65
+ "license": "MIT"
66
+ }
@@ -11,7 +11,7 @@
11
11
  * to identify exactly where the implementations diverge.
12
12
  */
13
13
 
14
- import { sha3_256 } from '@noble/hashes/sha3';
14
+ import { sha3_256 } from '@noble/hashes/sha3.js';
15
15
  import {
16
16
  setWotsLogger,
17
17
  disableWotsLogger,
@@ -1,7 +1,7 @@
1
1
  import { describe, it, expect } from "vitest";
2
2
  import { scriptToAddress } from "./derive";
3
3
  import { decodeMx } from "../../base32/src/minima32";
4
- import { bytesToHex } from "@noble/hashes/utils";
4
+ import { bytesToHex } from "@noble/hashes/utils.js";
5
5
 
6
6
  describe("Script → Mx (Minima oracles)", () => {
7
7
  it("RETURN TRUE", () => {
package/src/bip39.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * - convertStringToSeed(): Hashes phrase bytes with SHA3-256
13
13
  */
14
14
 
15
- import { sha3_256 } from '@noble/hashes/sha3';
15
+ import { sha3_256 } from '@noble/hashes/sha3.js';
16
16
 
17
17
  /**
18
18
  * Official BIP39 English word list (2048 words)
@@ -13,7 +13,7 @@
13
13
  * The canonical implementations are in Streamable.ts which uses bigint for precision.
14
14
  */
15
15
 
16
- import { sha3_256 } from '@noble/hashes/sha3';
16
+ import { sha3_256 } from '@noble/hashes/sha3.js';
17
17
  import {
18
18
  writeMiniNumber as streamableWriteMiniNumber,
19
19
  writeMiniData as streamableWriteMiniData,
package/src/minima32.ts CHANGED
@@ -40,7 +40,7 @@ export function decodeMxRadix32Frame(mx: string): Uint8Array {
40
40
  return bigIntToBytes(x);
41
41
  }
42
42
 
43
- import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3';
43
+ import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3.js';
44
44
 
45
45
  /** Encode raw 32 bytes to Mx address with frame and checksum */
46
46
  export function makeMxAddress(root32: Uint8Array): string {
package/src/mmr.d.ts CHANGED
@@ -150,4 +150,10 @@ export declare function verifyMMRProof(leafPubkey: Bytes, proof: MMRProof, expec
150
150
  export declare function deserializeMMRProof(data: Bytes): {
151
151
  proof: MMRProof;
152
152
  blockTime: bigint;
153
+ bytesRead: number;
154
+ };
155
+ export declare function parseMMRProofFromHex(data: Bytes): {
156
+ proof: MMRProof;
157
+ blockTime: bigint;
158
+ bytesRead: number;
153
159
  };
package/src/mmr.js CHANGED
@@ -9,6 +9,7 @@ exports.createMMRDataParentNode = createMMRDataParentNode;
9
9
  exports.calculateProofRoot = calculateProofRoot;
10
10
  exports.verifyMMRProof = verifyMMRProof;
11
11
  exports.deserializeMMRProof = deserializeMMRProof;
12
+ exports.parseMMRProofFromHex = deserializeMMRProof;
12
13
  // packages/totem-sdk/packages/core/src/mmr.ts
13
14
  // Full MMR implementation matching Minima's MMR.java, MMRData.java, and TreeKeyNode.java
14
15
  const sha3_1 = require("@noble/hashes/sha3");
@@ -326,7 +327,7 @@ function deserializeMMRProof(data) {
326
327
  offset += cvRead;
327
328
  chunks.push({ isLeft, mmrData: { data: hashData, value: chunkValue } });
328
329
  }
329
- return { proof: { chunks }, blockTime };
330
+ return { proof: { chunks }, blockTime, bytesRead: offset };
330
331
  }
331
332
  /**
332
333
  * Read a MiniNumber from bytes at the given offset
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect } from "vitest";
2
2
  import { mmrRootFromSingleLeaf } from "./mmr";
3
- import { bytesToHex } from "@noble/hashes/utils";
3
+ import { bytesToHex } from "@noble/hashes/utils.js";
4
4
 
5
5
  const enc = (s: string) => new TextEncoder().encode(s);
6
6
 
package/src/mmr.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // packages/totem-sdk/packages/core/src/mmr.ts
2
2
  // Full MMR implementation matching Minima's MMR.java, MMRData.java, and TreeKeyNode.java
3
- import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3';
3
+ import { sha3_256 as nobleSha3 } from '@noble/hashes/sha3.js';
4
4
  import { serializeMiniNumber, serializeMiniData, writeHashToStream, javaHashAllObjects } from "./javaStreamables.js";
5
5
 
6
6
  // Import canonical wire serialization from Streamable.ts (single source of truth)
@@ -365,7 +365,7 @@ export function verifyMMRProof(leafPubkey: Bytes, proof: MMRProof, expectedRoot:
365
365
  *
366
366
  * @returns { proof: MMRProof, blockTime: bigint }
367
367
  */
368
- export function parseMMRProofFromHex(data: Bytes): { proof: MMRProof; blockTime: bigint } {
368
+ export function parseMMRProofFromHex(data: Bytes): { proof: MMRProof; blockTime: bigint; bytesRead: number } {
369
369
  let offset = 0;
370
370
 
371
371
  // Read blockTime as MiniNumber
@@ -395,7 +395,7 @@ export function parseMMRProofFromHex(data: Bytes): { proof: MMRProof; blockTime:
395
395
  chunks.push({ isLeft, mmrData: { data: hashData, value: chunkValue } });
396
396
  }
397
397
 
398
- return { proof: { chunks }, blockTime };
398
+ return { proof: { chunks }, blockTime, bytesRead: offset };
399
399
  }
400
400
 
401
401
  /**
@@ -14,9 +14,9 @@
14
14
  * for use with the EnhancedTransactionBuilder.
15
15
  */
16
16
 
17
- import { sha3_256 } from '@noble/hashes/sha3';
18
- import { sha256 } from '@noble/hashes/sha256';
19
- import { randomBytes } from '@noble/hashes/utils';
17
+ import { sha3_256 } from '@noble/hashes/sha3.js';
18
+ import { sha256 } from '@noble/hashes/sha2.js';
19
+ import { randomBytes } from '@noble/hashes/utils.js';
20
20
  import type {
21
21
  ScriptDescriptor,
22
22
  StateValue,
@@ -1,4 +1,4 @@
1
- import { sha3_256 } from '@noble/hashes/sha3';
1
+ import { sha3_256 } from '@noble/hashes/sha3.js';
2
2
  import type { MMRProof, MMRProofChunk } from '../mmr.js';
3
3
  import { serializeMMRProof } from '../mmr.js';
4
4
  import type { ScriptDescriptor, StateValue, ExternalSignature, ScriptProofResult, FlatMMRProofChunk, LegacyMMRProof } from './types.js';
@@ -11,7 +11,7 @@
11
11
  * digest won't match what the Minima node verifies, causing allsignaturesvalid=false.
12
12
  */
13
13
 
14
- import { sha3_256 } from '@noble/hashes/sha3';
14
+ import { sha3_256 } from '@noble/hashes/sha3.js';
15
15
  import {
16
16
  writeMiniNumber,
17
17
  writeMiniData,
package/src/treekey.js CHANGED
@@ -697,12 +697,8 @@ function deserializeTreeSignature(data) {
697
697
  offset += 4;
698
698
  const signature = data.slice(offset, offset + sigLen);
699
699
  offset += sigLen;
700
- // MMR proof - new format returns { proof, blockTime }
701
- const { proof: mmrProof } = (0, mmr_1.deserializeMMRProof)(data.slice(offset));
702
- // Calculate how many bytes the MMR proof consumed
703
- // Format: blockTime (MiniNumber: 3 bytes for 0) + length (MiniNumber: 3 bytes for count)
704
- // + each chunk (1 byte isLeft + 32 bytes hash + 3 bytes value MiniNumber)
705
- const mmrProofLen = 3 + 3 + (mmrProof.chunks.length * (1 + 32 + 3));
700
+ // MMR proof - returns { proof, blockTime, bytesRead }
701
+ const { proof: mmrProof, bytesRead: mmrProofLen } = (0, mmr_1.deserializeMMRProof)(data.slice(offset));
706
702
  offset += mmrProofLen;
707
703
  proofs.push({ leafPubkey, signature, mmrProof });
708
704
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  // Jest globals (describe, it, expect) are available in test environment
14
- import { sha3_256 } from '@noble/hashes/sha3';
14
+ import { sha3_256 } from '@noble/hashes/sha3.js';
15
15
  import {
16
16
  serializeMiniNumber,
17
17
  serializeMiniData,
package/src/treekey.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * Default structure: 3 levels x 64 keys = 64^3 = 262,144 one-time signatures
10
10
  */
11
11
 
12
- import { sha3_256 } from '@noble/hashes/sha3';
12
+ import { sha3_256 } from '@noble/hashes/sha3.js';
13
13
  import { deriveChainSeedJava, hashObject, serializeMiniNumber, serializeMiniData, derivePerAddressSeed } from './javaStreamables.js';
14
14
  import { derivePKdigest, deriveFullPublicKey, wotsSign, wotsVerifyDigest, hex } from './wots.js';
15
15
  import { getParamSet } from './params.js';
@@ -884,12 +884,8 @@ export function deserializeTreeSignature(data: Bytes): TreeSignature {
884
884
  const signature = data.slice(offset, offset + sigLen);
885
885
  offset += sigLen;
886
886
 
887
- // MMR proof - new format returns { proof, blockTime }
888
- const { proof: mmrProof } = parseMMRProofFromHex(data.slice(offset));
889
- // Calculate how many bytes the MMR proof consumed
890
- // Format: blockTime (MiniNumber: 3 bytes for 0) + length (MiniNumber: 3 bytes for count)
891
- // + each chunk (1 byte isLeft + 32 bytes hash + 3 bytes value MiniNumber)
892
- const mmrProofLen = 3 + 3 + (mmrProof.chunks.length * (1 + 32 + 3));
887
+ // MMR proof - returns { proof, blockTime, bytesRead }
888
+ const { proof: mmrProof, bytesRead: mmrProofLen } = parseMMRProofFromHex(data.slice(offset));
893
889
  offset += mmrProofLen;
894
890
 
895
891
  proofs.push({ leafPubkey, signature, mmrProof });
package/src/verify.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { sha3_256 } from '@noble/hashes/sha3';
1
+ import { sha3_256 } from '@noble/hashes/sha3.js';
2
2
  import { verifyTreeSignature, deserializeTreeSignature } from './treekey.js';
3
3
  import { scriptToAddress, addressToRoot } from './derive.js';
4
4
  import { scriptFromWotsPk } from './script.js';
package/src/wots.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  * Source: org.bouncycastle.pqc.crypto.gmss.util.{WinternitzOTSignature, WinternitzOTSVerify, GMSSRandom}
14
14
  */
15
15
 
16
- import { sha3_256 } from '@noble/hashes/sha3';
16
+ import { sha3_256 } from '@noble/hashes/sha3.js';
17
17
  import { getParamSet, ParamSet } from "./params.js";
18
18
  import { deriveChainSeedJava } from "./javaStreamables.js";
19
19
  import type { LoggerAdapter } from "./adapters/index.js";