@totemsdk/core 1.0.6 → 1.0.8
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 +90 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +9 -9
- package/src/index.ts +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @totemsdk/core
|
|
2
|
+
|
|
3
|
+
**The cryptographic engine — every other package depends on this.**
|
|
4
|
+
|
|
5
|
+
Zero production dependencies (only `@noble/hashes` as a peer). Provides quantum-resistant WOTS signatures, hierarchical TreeKey address derivation, BIP39 seed phrases, Merkle Mountain Range proofs, and byte-exact Minima Java-compatible transaction serialization.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @totemsdk/core @noble/hashes
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## What's inside
|
|
14
|
+
|
|
15
|
+
| Module | What it does |
|
|
16
|
+
|--------|-------------|
|
|
17
|
+
| **WOTS** | `wotsKeypairFromSeed`, `wotsSign`, `wotsVerify`, `wotsPkFromSig` — quantum-resistant Winternitz One-Time Signatures |
|
|
18
|
+
| **TreeKey** | `createPerAddressTreeKey`, `verifyTreeSignature` — 3-level hierarchical signing trees; one seed → many signing addresses |
|
|
19
|
+
| **BIP39** | `generateSeedPhrase`, `validatePhrase`, `phraseToSeed` — 24-word mnemonic generation and recovery |
|
|
20
|
+
| **MMR** | Full Merkle Mountain Range proof construction and verification for Minima's UTXO set |
|
|
21
|
+
| **Serialization** | `serializeCoin`, `serializeTransaction`, `computeTransactionDigest`, `buildMinimaCoin` — byte-identical to the Minima Java node |
|
|
22
|
+
| **Verification** | `verifySignatureDetailed`, `verifyTreeSignatureDetailed` — server-side auth helpers |
|
|
23
|
+
| **Lease/Watermark** | `LeaseStore`, `WatermarkStore`, `LeaseMonitor` — WOTS key-use accounting to prevent catastrophic key reuse |
|
|
24
|
+
| **TransactionService** | High-level prepare → sign → finalize lifecycle with receipt tracking |
|
|
25
|
+
| **MINIMA_CONSTANTS** | Canonical chain parameters (`WOTS_W=8`, `MAX_SIGNATURES=262144`, `ADDRESS_PREFIX="Mx"`) |
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### WOTS keypair and signing
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { wotsKeypairFromSeed, wotsSign, wotsVerify } from '@totemsdk/core';
|
|
33
|
+
|
|
34
|
+
const seed = crypto.getRandomValues(new Uint8Array(32));
|
|
35
|
+
const keypair = wotsKeypairFromSeed(seed, 0);
|
|
36
|
+
|
|
37
|
+
// Sign — each (seed, index) pair is one-time use
|
|
38
|
+
const signature = wotsSign(seed, 0, message);
|
|
39
|
+
|
|
40
|
+
// Verify
|
|
41
|
+
const ok = wotsVerify(signature, message, keypair.pk);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Per-address TreeKey (matches Minima Wallet.java)
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { createPerAddressTreeKey } from '@totemsdk/core';
|
|
48
|
+
|
|
49
|
+
// One independent 3-level tree per address index (0–63)
|
|
50
|
+
const treeKey = createPerAddressTreeKey(baseSeed, 0);
|
|
51
|
+
|
|
52
|
+
// Convert watermark (l1, l2) to a flat counter
|
|
53
|
+
const uses = l1 * 64 + l2;
|
|
54
|
+
treeKey.setUses(uses);
|
|
55
|
+
const { signature, publicKey, proofs } = treeKey.sign(data);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Address derivation and verification
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { scriptToAddress, publicKeyToScript, verifySignature } from '@totemsdk/core';
|
|
62
|
+
|
|
63
|
+
const script = publicKeyToScript(publicKeyHex);
|
|
64
|
+
const address = scriptToAddress(script); // "Mx..."
|
|
65
|
+
|
|
66
|
+
const ok = verifySignature(address, message, signatureHex, publicKeyHex);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Replay-safe challenge/response
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { createChallenge, validateChallenge } from '@totemsdk/core';
|
|
73
|
+
|
|
74
|
+
// Server: create a challenge
|
|
75
|
+
const challenge = createChallenge('my-dapp.example.com');
|
|
76
|
+
|
|
77
|
+
// Server: validate before accepting a signature
|
|
78
|
+
const { valid, error } = validateChallenge(challenge, {
|
|
79
|
+
maxAgeMs: 5 * 60 * 1000,
|
|
80
|
+
expectedDomain: 'my-dapp.example.com',
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## See also
|
|
85
|
+
|
|
86
|
+
- [`@totemsdk/connect`](../connect) — dApp gateway built on top of core
|
|
87
|
+
- [`@totemsdk/node`](../node) — core wired for Node.js server-side use
|
|
88
|
+
- [`@totemsdk/wots-lease`](../wots-lease) — cloud-coordinated WOTS key safety
|
|
89
|
+
- [`@totemsdk/tx-builder`](../tx-builder) — full transaction construction
|
|
90
|
+
- [`@totemsdk/root-identity`](../root-identity) — multi-address identity from one seed
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { LeaseStore, WatermarkStore, LeaseMonitor, prepareLease, finalizeLease,
|
|
|
8
8
|
export { TransactionService, TransactionLifecycle, TransactionLifecycleError, WatermarkExhaustedError, TransactionReceiptStore, type TransactionServiceConfig, type WotsSigningDependencies, type TransactionLifecycleConfig, type WatermarkSyncFunction, type PrepareResult, type TransactionReceiptStoreConfig, type PrepareRequest, type PrepareResponse, type SignRequest, type SignResult, type HierarchicalWitnessBundle, type WitnessBundle, type FinalizeRequest, type FinalizeResponse, type TransactionMetadata, type TransactionReceipt, type TransactionError, } from './tx/index.js';
|
|
9
9
|
export type { WotsIndices } from './tx/index.js';
|
|
10
10
|
export * from './utils.js';
|
|
11
|
-
export { F, hex, fromHex, u16be, u32be, assert32, h, prfChainSeed, toWinternitzDigits, baseWWithChecksum, derivePKdigest, wotsKeypairFromSeed, wotsSign, wotsSignLegacy, wotsPkFromSig, wotsVerify, wotsPublicKeyFromSeed, type WotsKeypair, type WotsSignature, } from './wots.js';
|
|
11
|
+
export { F, hex, fromHex, u16be, u32be, assert32, h, prfChainSeed, toWinternitzDigits, baseWWithChecksum, derivePKdigest, wotsKeypairFromSeed, wotsSign, wotsSignLegacy, wotsPkFromSig, wotsVerify, wotsVerifyDigest, wotsPublicKeyFromSeed, type WotsKeypair, type WotsSignature, } from './wots.js';
|
|
12
12
|
export * from './params.js';
|
|
13
13
|
export { serializeMiniNumber, serializeMiniData, hashAllObjects, deriveChainSeedJava, deriveChildTreeSeedJava, hashObject, serializeMiniNumberZERO, serializeMiniNumberONE, writeHashToStream, javaHashAllObjects, indexToMiniDataBytes, derivePerAddressSeed, createMMREntryNumber, serializeMMREntryNumber, serializeMMRData, serializeMMREntry, precomputeTransactionCoinID, type MMREntryNumber as JavaMMREntryNumber, type MMRData as JavaMMRData, type MMREntry as JavaMMREntry, } from './javaStreamables.js';
|
|
14
14
|
export { TreeKey, type KeyGenProgress, type ProgressCallback, TreeKeyNode, verifyTreeSignature, serializeTreeSignature, deserializeTreeSignature, getRootPublicKey, DEFAULT_KEYS_PER_LEVEL, DEFAULT_LEVELS, type SignatureProof, type TreeSignature, createPerAddressTreeKey, createPerAddressTreeKeyAsync, deriveAddressPublicKey, getPerAddressPublicKey, } from './treekey.js';
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export { TransactionService, TransactionLifecycle, TransactionLifecycleError, Wa
|
|
|
13
13
|
// Utilities first (canonical concatBytes source)
|
|
14
14
|
export * from './utils.js';
|
|
15
15
|
// WOTS Signatures - wots.concatBytes is intentionally shadowed by utils.concatBytes above
|
|
16
|
-
export { F, hex, fromHex, u16be, u32be, assert32, h, prfChainSeed, toWinternitzDigits, baseWWithChecksum, derivePKdigest, wotsKeypairFromSeed, wotsSign, wotsSignLegacy, wotsPkFromSig, wotsVerify, wotsPublicKeyFromSeed, } from './wots.js';
|
|
16
|
+
export { F, hex, fromHex, u16be, u32be, assert32, h, prfChainSeed, toWinternitzDigits, baseWWithChecksum, derivePKdigest, wotsKeypairFromSeed, wotsSign, wotsSignLegacy, wotsPkFromSig, wotsVerify, wotsVerifyDigest, wotsPublicKeyFromSeed, } from './wots.js';
|
|
17
17
|
// WOTS Params (from params.ts, imported by wots.ts)
|
|
18
18
|
export * from './params.js';
|
|
19
19
|
// Java-Compatible Serialization Helpers (for Minima-compatible seed derivation)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Core cryptographic primitives for Totem SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,12 +28,6 @@
|
|
|
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
|
-
},
|
|
37
31
|
"files": [
|
|
38
32
|
"dist",
|
|
39
33
|
"src",
|
|
@@ -62,5 +56,11 @@
|
|
|
62
56
|
"publishConfig": {
|
|
63
57
|
"access": "public"
|
|
64
58
|
},
|
|
65
|
-
"license": "MIT"
|
|
66
|
-
|
|
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
|
+
}
|