@totemsdk/core 1.2.6 → 1.2.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.
Files changed (96) hide show
  1. package/dist/MiniNumber.js +9 -1
  2. package/dist/canonical.d.ts +3 -0
  3. package/dist/canonical.js +22 -0
  4. package/dist/cjs/MiniNumber.d.ts +47 -0
  5. package/dist/cjs/MiniNumber.js +310 -0
  6. package/dist/cjs/Streamable.d.ts +268 -0
  7. package/dist/cjs/Streamable.js +439 -0
  8. package/dist/cjs/adapters/index.d.ts +190 -0
  9. package/dist/cjs/adapters/index.js +118 -0
  10. package/dist/cjs/adapters/types.d.ts +150 -0
  11. package/dist/cjs/adapters/types.js +81 -0
  12. package/dist/cjs/binio.d.ts +9 -0
  13. package/dist/cjs/binio.js +25 -0
  14. package/dist/cjs/bip39.d.ts +91 -0
  15. package/dist/cjs/bip39.js +434 -0
  16. package/dist/cjs/canonical.d.ts +3 -0
  17. package/dist/cjs/canonical.js +27 -0
  18. package/dist/cjs/derive.d.ts +2 -0
  19. package/dist/cjs/derive.js +13 -0
  20. package/dist/cjs/index.d.ts +49 -0
  21. package/dist/cjs/index.js +231 -0
  22. package/dist/cjs/javaStreamables.d.ts +254 -0
  23. package/dist/cjs/javaStreamables.js +391 -0
  24. package/dist/cjs/lease/LeaseMonitor.d.ts +44 -0
  25. package/dist/cjs/lease/LeaseMonitor.js +115 -0
  26. package/dist/cjs/lease/LeaseStore.d.ts +58 -0
  27. package/dist/cjs/lease/LeaseStore.js +151 -0
  28. package/dist/cjs/lease/WatermarkStore.d.ts +61 -0
  29. package/dist/cjs/lease/WatermarkStore.js +209 -0
  30. package/dist/cjs/lease/index.d.ts +14 -0
  31. package/dist/cjs/lease/index.js +22 -0
  32. package/dist/cjs/lease-client.d.ts +31 -0
  33. package/dist/cjs/lease-client.js +44 -0
  34. package/dist/cjs/legacy.d.ts +23 -0
  35. package/dist/cjs/legacy.js +163 -0
  36. package/dist/cjs/minima32.d.ts +18 -0
  37. package/dist/cjs/minima32.js +121 -0
  38. package/dist/cjs/minimaWireSerializer.d.ts +60 -0
  39. package/dist/cjs/minimaWireSerializer.js +77 -0
  40. package/dist/cjs/mmr.d.ts +157 -0
  41. package/dist/cjs/mmr.js +352 -0
  42. package/dist/cjs/mx.d.ts +1 -0
  43. package/dist/cjs/mx.js +10 -0
  44. package/dist/cjs/package.json +1 -0
  45. package/dist/cjs/params.d.ts +29 -0
  46. package/dist/cjs/params.js +20 -0
  47. package/dist/cjs/script.d.ts +7 -0
  48. package/dist/cjs/script.js +27 -0
  49. package/dist/cjs/scripts/contract-helpers.d.ts +252 -0
  50. package/dist/cjs/scripts/contract-helpers.js +407 -0
  51. package/dist/cjs/scripts/dapp-types.d.ts +119 -0
  52. package/dist/cjs/scripts/dapp-types.js +77 -0
  53. package/dist/cjs/scripts/index.d.ts +4 -0
  54. package/dist/cjs/scripts/index.js +38 -0
  55. package/dist/cjs/scripts/types.d.ts +81 -0
  56. package/dist/cjs/scripts/types.js +159 -0
  57. package/dist/cjs/scripts/witness-serializer.d.ts +29 -0
  58. package/dist/cjs/scripts/witness-serializer.js +306 -0
  59. package/dist/cjs/transaction.d.ts +106 -0
  60. package/dist/cjs/transaction.js +293 -0
  61. package/dist/cjs/treekey.d.ts +399 -0
  62. package/dist/cjs/treekey.js +827 -0
  63. package/dist/cjs/tx/TransactionLifecycle.d.ts +55 -0
  64. package/dist/cjs/tx/TransactionLifecycle.js +205 -0
  65. package/dist/cjs/tx/TransactionReceiptStore.d.ts +36 -0
  66. package/dist/cjs/tx/TransactionReceiptStore.js +93 -0
  67. package/dist/cjs/tx/TransactionService.d.ts +50 -0
  68. package/dist/cjs/tx/TransactionService.js +186 -0
  69. package/dist/cjs/tx/index.d.ts +13 -0
  70. package/dist/cjs/tx/index.js +20 -0
  71. package/dist/cjs/tx/types.d.ts +115 -0
  72. package/dist/cjs/tx/types.js +6 -0
  73. package/dist/cjs/util.d.ts +1 -0
  74. package/dist/cjs/util.js +5 -0
  75. package/dist/cjs/utils.d.ts +8 -0
  76. package/dist/cjs/utils.js +42 -0
  77. package/dist/cjs/verify.d.ts +18 -0
  78. package/dist/cjs/verify.js +174 -0
  79. package/dist/cjs/version.d.ts +12 -0
  80. package/dist/cjs/version.js +15 -0
  81. package/dist/cjs/wasm-sync.d.ts +71 -0
  82. package/dist/cjs/wasm-sync.js +97 -0
  83. package/dist/cjs/wots.d.ts +232 -0
  84. package/dist/cjs/wots.js +589 -0
  85. package/dist/index.d.ts +9 -3
  86. package/dist/index.js +25 -2
  87. package/dist/minimaWireSerializer.js +2 -2
  88. package/dist/mmr.js +1 -1
  89. package/dist/transaction.js +10 -10
  90. package/dist/treekey.js +14 -0
  91. package/dist/wasm-sync.d.ts +2 -2
  92. package/dist/wasm-sync.js +3 -1
  93. package/dist/wots.d.ts +1 -1
  94. package/package.json +84 -45
  95. package/dist/wasm-bridge.d.ts +0 -54
  96. package/dist/wasm-bridge.js +0 -303
@@ -0,0 +1,119 @@
1
+ export declare const TOTEM_SEND_TRANSACTION_VERSION = 1;
2
+ export type DAppTransactionIntent = 'send' | 'token_send' | 'swap' | 'liquidity_add' | 'liquidity_remove' | 'contract_call' | 'multisig' | 'timelock' | 'htlc' | 'custom';
3
+ export interface DAppStateVariable {
4
+ port: number;
5
+ value: string;
6
+ type?: 'number' | 'string' | 'hex' | 'address';
7
+ }
8
+ export interface DAppTransactionOutput {
9
+ address: string;
10
+ amount: string;
11
+ tokenId?: string;
12
+ state?: DAppStateVariable[];
13
+ storeState?: boolean;
14
+ script?: string;
15
+ scriptRef?: string;
16
+ }
17
+ export interface DAppTransactionInput {
18
+ coinId: string;
19
+ address?: string;
20
+ amount?: string;
21
+ tokenId?: string;
22
+ }
23
+ export interface DAppSwapParams {
24
+ fromTokenId: string;
25
+ toTokenId: string;
26
+ amountIn: string;
27
+ minAmountOut: string;
28
+ slippageBps?: number;
29
+ poolAddress?: string;
30
+ }
31
+ export interface DAppLiquidityParams {
32
+ poolAddress: string;
33
+ tokenAId: string;
34
+ tokenBId: string;
35
+ amountA?: string;
36
+ amountB?: string;
37
+ lpTokenAmount?: string;
38
+ }
39
+ export interface DAppMultisigParams {
40
+ requiredSignatures: number;
41
+ publicKeys: string[];
42
+ timeoutBlocks?: number;
43
+ }
44
+ export interface DAppTimelockParams {
45
+ releaseBlock: number;
46
+ fallbackAddress?: string;
47
+ }
48
+ export interface DAppHtlcParams {
49
+ hashlock: string;
50
+ timeoutBlocks: number;
51
+ recipientAddress: string;
52
+ refundAddress: string;
53
+ }
54
+ export interface DAppContractCallParams {
55
+ contractAddress: string;
56
+ method?: string;
57
+ args?: Record<string, string>;
58
+ script?: string;
59
+ }
60
+ export interface TotemSendTransactionRequest {
61
+ version: typeof TOTEM_SEND_TRANSACTION_VERSION;
62
+ intent: DAppTransactionIntent;
63
+ outputs: DAppTransactionOutput[];
64
+ inputs?: DAppTransactionInput[];
65
+ burn?: string;
66
+ memo?: string;
67
+ metadata?: {
68
+ appName?: string;
69
+ description?: string;
70
+ iconUrl?: string;
71
+ };
72
+ options?: {
73
+ verifyWithTotemidea?: boolean;
74
+ skipPreview?: boolean;
75
+ useSourceAddress?: string;
76
+ excludeAddresses?: string[];
77
+ };
78
+ swap?: DAppSwapParams;
79
+ liquidity?: DAppLiquidityParams;
80
+ multisig?: DAppMultisigParams;
81
+ timelock?: DAppTimelockParams;
82
+ htlc?: DAppHtlcParams;
83
+ contract?: DAppContractCallParams;
84
+ }
85
+ export interface TotemSendTransactionResponse {
86
+ success: boolean;
87
+ txpowid?: string;
88
+ status?: 'pending' | 'submitted' | 'confirmed' | 'rejected';
89
+ artifactId?: string;
90
+ digestHex?: string;
91
+ error?: string;
92
+ errorCode?: TotemTransactionErrorCode;
93
+ verification?: {
94
+ totemideaValid?: boolean;
95
+ totemideaWarnings?: string[];
96
+ totemideaNotes?: string[];
97
+ };
98
+ }
99
+ export type TotemTransactionErrorCode = 'INVALID_REQUEST' | 'INSUFFICIENT_FUNDS' | 'PERMISSION_DENIED' | 'USER_REJECTED' | 'SITE_NOT_CONNECTED' | 'SPENDING_LIMIT_EXCEEDED' | 'TOKEN_NOT_ALLOWED' | 'VERIFICATION_FAILED' | 'BUILD_FAILED' | 'SIGN_FAILED' | 'BROADCAST_FAILED' | 'TIMEOUT';
100
+ export interface SiteTransactionPermission {
101
+ origin: string;
102
+ grantedAt: number;
103
+ expiresAt: number;
104
+ scopes: TransactionScope[];
105
+ }
106
+ export interface TransactionScope {
107
+ tokenId: string;
108
+ tokenSymbol?: string;
109
+ maxAmountPerTx: string;
110
+ maxDailyAmount: string;
111
+ dailyUsed: string;
112
+ lastResetDate: string;
113
+ allowedIntents: DAppTransactionIntent[];
114
+ }
115
+ export declare function validateSendTransactionRequest(request: unknown): {
116
+ valid: boolean;
117
+ errors: string[];
118
+ };
119
+ export declare function simpleTotemSendRequest(to: string, amount: string, tokenId?: string): TotemSendTransactionRequest;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TOTEM_SEND_TRANSACTION_VERSION = void 0;
4
+ exports.validateSendTransactionRequest = validateSendTransactionRequest;
5
+ exports.simpleTotemSendRequest = simpleTotemSendRequest;
6
+ exports.TOTEM_SEND_TRANSACTION_VERSION = 1;
7
+ function validateSendTransactionRequest(request) {
8
+ const errors = [];
9
+ if (!request || typeof request !== 'object') {
10
+ return { valid: false, errors: ['Request must be an object'] };
11
+ }
12
+ const req = request;
13
+ if (req.version !== exports.TOTEM_SEND_TRANSACTION_VERSION) {
14
+ errors.push(`Invalid version: expected ${exports.TOTEM_SEND_TRANSACTION_VERSION}, got ${req.version}`);
15
+ }
16
+ const validIntents = [
17
+ 'send', 'token_send', 'swap', 'liquidity_add', 'liquidity_remove',
18
+ 'contract_call', 'multisig', 'timelock', 'htlc', 'custom'
19
+ ];
20
+ if (!validIntents.includes(req.intent)) {
21
+ errors.push(`Invalid intent: ${req.intent}. Must be one of: ${validIntents.join(', ')}`);
22
+ }
23
+ if (!Array.isArray(req.outputs) || req.outputs.length === 0) {
24
+ errors.push('outputs must be a non-empty array');
25
+ }
26
+ else {
27
+ for (let i = 0; i < req.outputs.length; i++) {
28
+ const output = req.outputs[i];
29
+ if (!output.address || typeof output.address !== 'string') {
30
+ errors.push(`outputs[${i}].address is required and must be a string`);
31
+ }
32
+ if (!output.amount || typeof output.amount !== 'string') {
33
+ errors.push(`outputs[${i}].amount is required and must be a string`);
34
+ }
35
+ const amountNum = parseFloat(output.amount);
36
+ if (isNaN(amountNum) || amountNum <= 0) {
37
+ errors.push(`outputs[${i}].amount must be a positive number`);
38
+ }
39
+ }
40
+ }
41
+ if (req.burn !== undefined) {
42
+ const burnNum = parseFloat(req.burn);
43
+ if (isNaN(burnNum) || burnNum < 0) {
44
+ errors.push('burn must be a non-negative number string');
45
+ }
46
+ }
47
+ if (req.intent === 'swap' && !req.swap) {
48
+ errors.push('swap params required for swap intent');
49
+ }
50
+ if ((req.intent === 'liquidity_add' || req.intent === 'liquidity_remove') && !req.liquidity) {
51
+ errors.push('liquidity params required for liquidity intent');
52
+ }
53
+ if (req.intent === 'multisig' && !req.multisig) {
54
+ errors.push('multisig params required for multisig intent');
55
+ }
56
+ if (req.intent === 'timelock' && !req.timelock) {
57
+ errors.push('timelock params required for timelock intent');
58
+ }
59
+ if (req.intent === 'htlc' && !req.htlc) {
60
+ errors.push('htlc params required for htlc intent');
61
+ }
62
+ if (req.intent === 'contract_call' && !req.contract) {
63
+ errors.push('contract params required for contract_call intent');
64
+ }
65
+ return { valid: errors.length === 0, errors };
66
+ }
67
+ function simpleTotemSendRequest(to, amount, tokenId) {
68
+ return {
69
+ version: exports.TOTEM_SEND_TRANSACTION_VERSION,
70
+ intent: tokenId && tokenId !== '0x00' ? 'token_send' : 'send',
71
+ outputs: [{
72
+ address: to,
73
+ amount,
74
+ tokenId: tokenId || '0x00'
75
+ }]
76
+ };
77
+ }
@@ -0,0 +1,4 @@
1
+ export * from './types.js';
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';
4
+ export * from './contract-helpers.js';
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
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;
18
+ __exportStar(require("./types.js"), exports);
19
+ __exportStar(require("./dapp-types.js"), exports);
20
+ var witness_serializer_js_1 = require("./witness-serializer.js");
21
+ Object.defineProperty(exports, "encodeMiniNumber", { enumerable: true, get: function () { return witness_serializer_js_1.encodeMiniNumber; } });
22
+ Object.defineProperty(exports, "encodeMiniData", { enumerable: true, get: function () { return witness_serializer_js_1.encodeMiniData; } });
23
+ Object.defineProperty(exports, "encodeMiniString", { enumerable: true, get: function () { return witness_serializer_js_1.encodeMiniString; } });
24
+ Object.defineProperty(exports, "serializeMMRProofChunk", { enumerable: true, get: function () { return witness_serializer_js_1.serializeMMRProofChunk; } });
25
+ Object.defineProperty(exports, "serializeScriptProofWithProof", { enumerable: true, get: function () { return witness_serializer_js_1.serializeScriptProofWithProof; } });
26
+ Object.defineProperty(exports, "STATETYPE_HEX", { enumerable: true, get: function () { return witness_serializer_js_1.STATETYPE_HEX; } });
27
+ Object.defineProperty(exports, "STATETYPE_NUMBER", { enumerable: true, get: function () { return witness_serializer_js_1.STATETYPE_NUMBER; } });
28
+ Object.defineProperty(exports, "STATETYPE_STRING", { enumerable: true, get: function () { return witness_serializer_js_1.STATETYPE_STRING; } });
29
+ Object.defineProperty(exports, "STATETYPE_BOOL", { enumerable: true, get: function () { return witness_serializer_js_1.STATETYPE_BOOL; } });
30
+ Object.defineProperty(exports, "encodeStateValue", { enumerable: true, get: function () { return witness_serializer_js_1.encodeStateValue; } });
31
+ Object.defineProperty(exports, "serializeStateVariables", { enumerable: true, get: function () { return witness_serializer_js_1.serializeStateVariables; } });
32
+ Object.defineProperty(exports, "buildScriptProofFromDescriptor", { enumerable: true, get: function () { return witness_serializer_js_1.buildScriptProofFromDescriptor; } });
33
+ Object.defineProperty(exports, "deduplicateScriptDescriptors", { enumerable: true, get: function () { return witness_serializer_js_1.deduplicateScriptDescriptors; } });
34
+ Object.defineProperty(exports, "serializeExtraScripts", { enumerable: true, get: function () { return witness_serializer_js_1.serializeExtraScripts; } });
35
+ Object.defineProperty(exports, "aggregateSignatures", { enumerable: true, get: function () { return witness_serializer_js_1.aggregateSignatures; } });
36
+ Object.defineProperty(exports, "validateExternalSignature", { enumerable: true, get: function () { return witness_serializer_js_1.validateExternalSignature; } });
37
+ Object.defineProperty(exports, "computeScriptAddress", { enumerable: true, get: function () { return witness_serializer_js_1.computeScriptAddress; } });
38
+ __exportStar(require("./contract-helpers.js"), exports);
@@ -0,0 +1,81 @@
1
+ import type { MMRProofChunk, MMRProof } from '../mmr.js';
2
+ export type { MMRProof };
3
+ export type StateVariableType = 'STATE' | 'PREVSTATE' | 'SAMESTATE';
4
+ export interface StateValue {
5
+ port: number;
6
+ value: string | bigint | Uint8Array | boolean;
7
+ type: 'bool' | 'number' | 'hex' | 'string';
8
+ }
9
+ export interface VerifyOutExpectation {
10
+ inputIndex: number | '@INPUT';
11
+ outputAddress: string;
12
+ amount: string | bigint;
13
+ tokenId: string;
14
+ keepState: boolean;
15
+ }
16
+ export type ScriptType = 'signedby' | 'multisig' | 'multisig_mofn' | 'timelock' | 'htlc' | 'mast' | 'exchange' | 'vault' | 'flashcash' | 'slowcash' | 'stateful' | 'custom';
17
+ export interface ScriptDescriptor {
18
+ address: string;
19
+ scriptType: ScriptType;
20
+ script: string;
21
+ wotsRootPublicKey?: string;
22
+ mastProof?: MMRProof;
23
+ extraScripts?: Map<string, string>;
24
+ stateVariables?: StateValue[];
25
+ storeState?: boolean;
26
+ verifyOutExpectations?: VerifyOutExpectation[];
27
+ timelockBlock?: bigint;
28
+ htlcHash?: string;
29
+ htlcPreimage?: string;
30
+ multisigKeys?: string[];
31
+ multisigThreshold?: number;
32
+ externalSignatures?: ExternalSignature[];
33
+ }
34
+ export interface ExternalSignature {
35
+ publicKey: string;
36
+ signature: string;
37
+ proof?: MMRProof;
38
+ signatureType: 'wots' | 'standard';
39
+ validated?: boolean;
40
+ }
41
+ export interface ScriptCatalogEntry {
42
+ address: string;
43
+ script: string;
44
+ scriptType: ScriptType;
45
+ createdAt: number;
46
+ lastUsed: number;
47
+ }
48
+ export interface ScriptProofResult {
49
+ script: string;
50
+ proof: MMRProof;
51
+ serialized: Uint8Array;
52
+ }
53
+ export interface TransactionRoundState {
54
+ round: number;
55
+ previousRound: number;
56
+ preservedPorts: number[];
57
+ newStates: StateValue[];
58
+ }
59
+ export interface FlatMMRProofChunk {
60
+ isLeft: boolean;
61
+ data: Uint8Array;
62
+ }
63
+ export interface LegacyMMRProof {
64
+ blockTime: bigint;
65
+ proofChain: FlatMMRProofChunk[];
66
+ }
67
+ export declare function convertFlatChunkToSDK(chunk: FlatMMRProofChunk): MMRProofChunk;
68
+ export declare function convertLegacyProofToSDK(legacy: LegacyMMRProof): {
69
+ proof: MMRProof;
70
+ blockTime: bigint;
71
+ };
72
+ export declare function createEmptyMMRProof(): MMRProof;
73
+ export declare function createSignedByDescriptor(address: string, wotsRootPublicKey: string): ScriptDescriptor;
74
+ export declare function createMultisigDescriptor(address: string, publicKey1: string, publicKey2: string, ownPublicKey: string): ScriptDescriptor;
75
+ export declare function createMofNMultisigDescriptor(address: string, threshold: number, publicKeys: string[], ownPublicKey: string): ScriptDescriptor;
76
+ export declare function createTimelockDescriptor(address: string, publicKey: string, unlockBlock: bigint): ScriptDescriptor;
77
+ export declare function createHTLCDescriptor(address: string, ownerPublicKey: string, recipientPublicKey: string, hashLock: string, timeoutBlock: bigint, isOwner: boolean, preimage?: string): ScriptDescriptor;
78
+ export declare function createMASTDescriptor(address: string, rootHash: string, branchScript: string, branchProof: string, wotsPublicKey?: string): ScriptDescriptor;
79
+ export declare function createExchangeDescriptor(address: string, ownerPublicKey: string, desiredAddress: string, desiredAmount: string, desiredTokenId: string): ScriptDescriptor;
80
+ export declare function createFlashCashDescriptor(address: string, ownerPublicKey: string, interestMultiplier?: string): ScriptDescriptor;
81
+ export declare function createSlowCashDescriptor(address: string, ownerPublicKey: string, withdrawalPercent?: string, cooldownBlocks?: bigint): ScriptDescriptor;
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertFlatChunkToSDK = convertFlatChunkToSDK;
4
+ exports.convertLegacyProofToSDK = convertLegacyProofToSDK;
5
+ exports.createEmptyMMRProof = createEmptyMMRProof;
6
+ exports.createSignedByDescriptor = createSignedByDescriptor;
7
+ exports.createMultisigDescriptor = createMultisigDescriptor;
8
+ exports.createMofNMultisigDescriptor = createMofNMultisigDescriptor;
9
+ exports.createTimelockDescriptor = createTimelockDescriptor;
10
+ exports.createHTLCDescriptor = createHTLCDescriptor;
11
+ exports.createMASTDescriptor = createMASTDescriptor;
12
+ exports.createExchangeDescriptor = createExchangeDescriptor;
13
+ exports.createFlashCashDescriptor = createFlashCashDescriptor;
14
+ exports.createSlowCashDescriptor = createSlowCashDescriptor;
15
+ function kissHex(hex) {
16
+ const raw = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
17
+ return '0x' + raw.toUpperCase();
18
+ }
19
+ function convertFlatChunkToSDK(chunk) {
20
+ return {
21
+ isLeft: chunk.isLeft,
22
+ mmrData: { data: chunk.data, value: 0n }
23
+ };
24
+ }
25
+ function convertLegacyProofToSDK(legacy) {
26
+ return {
27
+ proof: {
28
+ chunks: legacy.proofChain.map(convertFlatChunkToSDK)
29
+ },
30
+ blockTime: legacy.blockTime
31
+ };
32
+ }
33
+ function createEmptyMMRProof() {
34
+ return { chunks: [] };
35
+ }
36
+ function createSignedByDescriptor(address, wotsRootPublicKey) {
37
+ return {
38
+ address,
39
+ scriptType: 'signedby',
40
+ script: `RETURN SIGNEDBY(${kissHex(wotsRootPublicKey)})`,
41
+ wotsRootPublicKey,
42
+ mastProof: createEmptyMMRProof(),
43
+ storeState: false
44
+ };
45
+ }
46
+ function createMultisigDescriptor(address, publicKey1, publicKey2, ownPublicKey) {
47
+ return {
48
+ address,
49
+ scriptType: 'multisig',
50
+ script: `RETURN SIGNEDBY(${kissHex(publicKey1)}) AND SIGNEDBY(${kissHex(publicKey2)})`,
51
+ wotsRootPublicKey: ownPublicKey,
52
+ multisigKeys: [publicKey1, publicKey2],
53
+ multisigThreshold: 2,
54
+ mastProof: createEmptyMMRProof(),
55
+ storeState: false
56
+ };
57
+ }
58
+ function createMofNMultisigDescriptor(address, threshold, publicKeys, ownPublicKey) {
59
+ const formattedKeys = publicKeys.map(pk => kissHex(pk)).join(' ');
60
+ return {
61
+ address,
62
+ scriptType: 'multisig_mofn',
63
+ script: `RETURN MULTISIG(${threshold} ${formattedKeys})`,
64
+ wotsRootPublicKey: ownPublicKey,
65
+ multisigKeys: publicKeys,
66
+ multisigThreshold: threshold,
67
+ mastProof: createEmptyMMRProof(),
68
+ storeState: false
69
+ };
70
+ }
71
+ function createTimelockDescriptor(address, publicKey, unlockBlock) {
72
+ return {
73
+ address,
74
+ scriptType: 'timelock',
75
+ script: `RETURN SIGNEDBY(${kissHex(publicKey)}) AND @BLOCK GT ${unlockBlock}`,
76
+ wotsRootPublicKey: publicKey,
77
+ timelockBlock: unlockBlock,
78
+ mastProof: createEmptyMMRProof(),
79
+ storeState: false
80
+ };
81
+ }
82
+ function createHTLCDescriptor(address, ownerPublicKey, recipientPublicKey, hashLock, timeoutBlock, isOwner, preimage) {
83
+ const script = `IF @BLOCK GT ${timeoutBlock} AND SIGNEDBY(${kissHex(ownerPublicKey)}) THEN RETURN TRUE ENDIF RETURN (SIGNEDBY(${kissHex(recipientPublicKey)}) AND SHA3(STATE(1)) EQ ${kissHex(hashLock)})`;
84
+ const descriptor = {
85
+ address,
86
+ scriptType: 'htlc',
87
+ script,
88
+ wotsRootPublicKey: isOwner ? ownerPublicKey : recipientPublicKey,
89
+ htlcHash: hashLock,
90
+ timelockBlock: timeoutBlock,
91
+ mastProof: createEmptyMMRProof(),
92
+ storeState: false
93
+ };
94
+ if (preimage) {
95
+ descriptor.htlcPreimage = preimage;
96
+ descriptor.stateVariables = [{ port: 1, value: preimage, type: 'string' }];
97
+ }
98
+ return descriptor;
99
+ }
100
+ function createMASTDescriptor(address, rootHash, branchScript, branchProof, wotsPublicKey) {
101
+ return {
102
+ address,
103
+ scriptType: 'mast',
104
+ script: `MAST ${kissHex(rootHash)}`,
105
+ wotsRootPublicKey: wotsPublicKey,
106
+ extraScripts: new Map([[branchScript, branchProof]]),
107
+ mastProof: createEmptyMMRProof(),
108
+ storeState: false
109
+ };
110
+ }
111
+ function createExchangeDescriptor(address, ownerPublicKey, desiredAddress, desiredAmount, desiredTokenId) {
112
+ const ownerPk = kissHex(ownerPublicKey);
113
+ const script = `IF SIGNEDBY(PREVSTATE(0)) THEN RETURN TRUE ENDIF ASSERT VERIFYOUT(@INPUT PREVSTATE(1) PREVSTATE(2) PREVSTATE(3) TRUE) RETURN TRUE`;
114
+ return {
115
+ address,
116
+ scriptType: 'exchange',
117
+ script,
118
+ wotsRootPublicKey: ownerPublicKey,
119
+ stateVariables: [
120
+ { port: 0, value: ownerPk, type: 'hex' },
121
+ { port: 1, value: desiredAddress, type: 'hex' },
122
+ { port: 2, value: desiredAmount, type: 'number' },
123
+ { port: 3, value: desiredTokenId, type: 'hex' }
124
+ ],
125
+ verifyOutExpectations: [{
126
+ inputIndex: '@INPUT',
127
+ outputAddress: desiredAddress,
128
+ amount: desiredAmount,
129
+ tokenId: desiredTokenId,
130
+ keepState: true
131
+ }],
132
+ mastProof: createEmptyMMRProof(),
133
+ storeState: true
134
+ };
135
+ }
136
+ function createFlashCashDescriptor(address, ownerPublicKey, interestMultiplier = '1.01') {
137
+ const script = `IF SIGNEDBY(PREVSTATE(1)) THEN RETURN TRUE ENDIF ASSERT SAMESTATE(1 1) RETURN VERIFYOUT(@INPUT @ADDRESS @AMOUNT*${interestMultiplier} @TOKENID TRUE)`;
138
+ return {
139
+ address,
140
+ scriptType: 'flashcash',
141
+ script,
142
+ wotsRootPublicKey: ownerPublicKey,
143
+ stateVariables: [{ port: 1, value: ownerPublicKey, type: 'hex' }],
144
+ mastProof: createEmptyMMRProof(),
145
+ storeState: true
146
+ };
147
+ }
148
+ function createSlowCashDescriptor(address, ownerPublicKey, withdrawalPercent = '0.9', cooldownBlocks = 10000n) {
149
+ const script = `IF @COINAGE LT ${cooldownBlocks} THEN RETURN FALSE ENDIF ASSERT SIGNEDBY(${kissHex(ownerPublicKey)}) AND VERIFYOUT(@INPUT @ADDRESS @AMOUNT*${withdrawalPercent} @TOKENID TRUE)`;
150
+ return {
151
+ address,
152
+ scriptType: 'slowcash',
153
+ script,
154
+ wotsRootPublicKey: ownerPublicKey,
155
+ timelockBlock: cooldownBlocks,
156
+ mastProof: createEmptyMMRProof(),
157
+ storeState: false
158
+ };
159
+ }
@@ -0,0 +1,29 @@
1
+ import type { MMRProof, MMRProofChunk } from '../mmr.js';
2
+ import type { ScriptDescriptor, StateValue, ExternalSignature, ScriptProofResult } from './types.js';
3
+ declare function concat(...arrays: Uint8Array[]): Uint8Array;
4
+ export declare function encodeMiniNumber(value: bigint, scale?: number): Uint8Array;
5
+ export declare function encodeMiniData(data: Uint8Array): Uint8Array;
6
+ export declare function encodeMiniString(str: string): Uint8Array;
7
+ export declare function serializeMMRProofChunk(chunk: MMRProofChunk): Uint8Array;
8
+ export declare function serializeRealMMRProof(proof: MMRProof, blockTime?: bigint): Uint8Array;
9
+ export declare function parseMMRProofFromHex(proofHex: string): {
10
+ proof: MMRProof;
11
+ blockTime: bigint;
12
+ };
13
+ export declare function serializeScriptProofWithProof(script: string, proof: MMRProof, blockTime?: bigint): Uint8Array;
14
+ export declare const STATETYPE_HEX = 1;
15
+ export declare const STATETYPE_NUMBER = 2;
16
+ export declare const STATETYPE_STRING = 4;
17
+ export declare const STATETYPE_BOOL = 8;
18
+ export declare function encodeStateValue(stateValue: StateValue): Uint8Array;
19
+ export declare function serializeStateVariables(stateValues: StateValue[]): Uint8Array;
20
+ export declare function buildScriptProofFromDescriptor(descriptor: ScriptDescriptor): ScriptProofResult;
21
+ export declare function deduplicateScriptDescriptors(descriptors: ScriptDescriptor[]): Map<string, ScriptDescriptor>;
22
+ export declare function serializeExtraScripts(extraScripts: Map<string, string>): Uint8Array;
23
+ export declare function aggregateSignatures(totemSignature: {
24
+ publicKey: Uint8Array;
25
+ signature: Uint8Array;
26
+ }, externalSignatures: ExternalSignature[]): Uint8Array[];
27
+ export declare function validateExternalSignature(signature: ExternalSignature, transactionDigest: Uint8Array): boolean;
28
+ export declare function computeScriptAddress(script: string): string;
29
+ export { concat };