@totemsdk/core 1.0.9 → 1.0.11

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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -5
  3. package/dist/Streamable.js +54 -31
  4. package/dist/adapters/index.js +18 -8
  5. package/dist/adapters/types.js +19 -8
  6. package/dist/binio.js +5 -1
  7. package/dist/bip39.js +24 -14
  8. package/dist/derive.js +11 -7
  9. package/dist/index.js +130 -22
  10. package/dist/javaStreamables.js +49 -30
  11. package/dist/lease/LeaseMonitor.js +7 -3
  12. package/dist/lease/LeaseStore.js +7 -3
  13. package/dist/lease/WatermarkStore.js +7 -3
  14. package/dist/lease/index.js +13 -4
  15. package/dist/lease-client.js +8 -3
  16. package/dist/minima32.js +22 -13
  17. package/dist/minimaWireSerializer.js +20 -14
  18. package/dist/mmr.js +35 -23
  19. package/dist/mx.js +10 -1
  20. package/dist/params.js +9 -5
  21. package/dist/script.js +12 -7
  22. package/dist/scripts/contract-helpers.js +37 -26
  23. package/dist/scripts/dapp-types.js +11 -6
  24. package/dist/scripts/index.js +38 -4
  25. package/dist/scripts/types.js +26 -12
  26. package/dist/scripts/witness-serializer.js +48 -30
  27. package/dist/transaction.js +55 -46
  28. package/dist/treekey.js +74 -58
  29. package/dist/tx/TransactionLifecycle.js +11 -5
  30. package/dist/tx/TransactionReceiptStore.js +7 -3
  31. package/dist/tx/TransactionService.js +14 -10
  32. package/dist/tx/index.js +11 -3
  33. package/dist/tx/types.js +2 -1
  34. package/dist/util.js +5 -1
  35. package/dist/utils.js +12 -5
  36. package/dist/verify.js +36 -25
  37. package/dist/version.js +5 -2
  38. package/dist/wots.d.ts +2 -2
  39. package/dist/wots.js +94 -64
  40. package/package.json +50 -6
  41. package/src/Streamable.d.ts +0 -268
  42. package/src/Streamable.js +0 -416
  43. package/src/Streamable.ts +0 -567
  44. package/src/__tests__/Streamable.parity.test.ts +0 -422
  45. package/src/__tests__/perAddressDerivation.parity.test.ts +0 -152
  46. package/src/__tests__/roottree-prepare.test.ts +0 -101
  47. package/src/__tests__/wots-parity.test.ts +0 -289
  48. package/src/adapters/index.d.ts +0 -190
  49. package/src/adapters/index.js +0 -117
  50. package/src/adapters/index.ts +0 -301
  51. package/src/adapters/types.ts +0 -235
  52. package/src/addr.oracle.test.ts +0 -25
  53. package/src/address.test.ts +0 -55
  54. package/src/binio.ts +0 -21
  55. package/src/bip39.d.ts +0 -91
  56. package/src/bip39.js +0 -427
  57. package/src/bip39.ts +0 -432
  58. package/src/derive.d.ts +0 -2
  59. package/src/derive.js +0 -13
  60. package/src/derive.ts +0 -11
  61. package/src/index.d.ts +0 -26
  62. package/src/index.js +0 -128
  63. package/src/index.test.ts +0 -5
  64. package/src/index.ts +0 -221
  65. package/src/javaStreamables.d.ts +0 -233
  66. package/src/javaStreamables.js +0 -332
  67. package/src/javaStreamables.ts +0 -403
  68. package/src/lease/LeaseMonitor.d.ts +0 -44
  69. package/src/lease/LeaseMonitor.js +0 -111
  70. package/src/lease/LeaseMonitor.ts +0 -157
  71. package/src/lease/LeaseStore.d.ts +0 -57
  72. package/src/lease/LeaseStore.js +0 -148
  73. package/src/lease/LeaseStore.ts +0 -203
  74. package/src/lease/WatermarkStore.d.ts +0 -61
  75. package/src/lease/WatermarkStore.js +0 -206
  76. package/src/lease/WatermarkStore.ts +0 -270
  77. package/src/lease/index.d.ts +0 -14
  78. package/src/lease/index.js +0 -22
  79. package/src/lease/index.ts +0 -41
  80. package/src/lease-client.d.ts +0 -31
  81. package/src/lease-client.js +0 -44
  82. package/src/lease-client.ts +0 -69
  83. package/src/minima32.d.ts +0 -10
  84. package/src/minima32.js +0 -113
  85. package/src/minima32.test.ts +0 -11
  86. package/src/minima32.ts +0 -127
  87. package/src/minimaWireSerializer.d.ts +0 -189
  88. package/src/minimaWireSerializer.js +0 -311
  89. package/src/minimaWireSerializer.test.ts +0 -466
  90. package/src/minimaWireSerializer.ts +0 -117
  91. package/src/mmr.d.ts +0 -157
  92. package/src/mmr.js +0 -340
  93. package/src/mmr.oracle.test.ts +0 -28
  94. package/src/mmr.ts +0 -429
  95. package/src/mx.test.ts +0 -25
  96. package/src/mx.ts +0 -1
  97. package/src/params.d.ts +0 -29
  98. package/src/params.d.ts.map +0 -1
  99. package/src/params.js +0 -20
  100. package/src/params.js.map +0 -1
  101. package/src/params.ts +0 -44
  102. package/src/script.d.ts +0 -7
  103. package/src/script.js +0 -27
  104. package/src/script.ts +0 -24
  105. package/src/scripts/contract-helpers.ts +0 -609
  106. package/src/scripts/dapp-types.ts +0 -240
  107. package/src/scripts/index.ts +0 -22
  108. package/src/scripts/types.d.ts +0 -81
  109. package/src/scripts/types.js +0 -145
  110. package/src/scripts/types.ts +0 -247
  111. package/src/scripts/witness-serializer.ts +0 -384
  112. package/src/transaction.ts +0 -430
  113. package/src/treekey.d.ts +0 -383
  114. package/src/treekey.js +0 -774
  115. package/src/treekey.parity.test.ts +0 -459
  116. package/src/treekey.ts +0 -975
  117. package/src/tx/TransactionLifecycle.d.ts +0 -55
  118. package/src/tx/TransactionLifecycle.js +0 -188
  119. package/src/tx/TransactionLifecycle.ts +0 -280
  120. package/src/tx/TransactionReceiptStore.d.ts +0 -36
  121. package/src/tx/TransactionReceiptStore.js +0 -89
  122. package/src/tx/TransactionReceiptStore.ts +0 -112
  123. package/src/tx/TransactionService.d.ts +0 -31
  124. package/src/tx/TransactionService.js +0 -140
  125. package/src/tx/TransactionService.ts +0 -252
  126. package/src/tx/index.d.ts +0 -13
  127. package/src/tx/index.js +0 -20
  128. package/src/tx/index.ts +0 -44
  129. package/src/tx/types.d.ts +0 -80
  130. package/src/tx/types.js +0 -6
  131. package/src/tx/types.ts +0 -130
  132. package/src/util.d.ts +0 -1
  133. package/src/util.js +0 -5
  134. package/src/util.ts +0 -1
  135. package/src/utils.d.ts +0 -8
  136. package/src/utils.js +0 -42
  137. package/src/utils.ts +0 -38
  138. package/src/verify.ts +0 -210
  139. package/src/version.ts +0 -13
  140. package/src/wots.d.ts +0 -224
  141. package/src/wots.d.ts.map +0 -1
  142. package/src/wots.js +0 -565
  143. package/src/wots.js.map +0 -1
  144. package/src/wots.ts +0 -651
  145. package/test-vectors.json +0 -45
@@ -1,240 +0,0 @@
1
- export const TOTEM_SEND_TRANSACTION_VERSION = 1;
2
-
3
- export type DAppTransactionIntent =
4
- | 'send'
5
- | 'token_send'
6
- | 'swap'
7
- | 'liquidity_add'
8
- | 'liquidity_remove'
9
- | 'contract_call'
10
- | 'multisig'
11
- | 'timelock'
12
- | 'htlc'
13
- | 'custom';
14
-
15
- export interface DAppStateVariable {
16
- port: number;
17
- value: string;
18
- type?: 'number' | 'string' | 'hex' | 'address';
19
- }
20
-
21
- export interface DAppTransactionOutput {
22
- address: string;
23
- amount: string;
24
- tokenId?: string;
25
- state?: DAppStateVariable[];
26
- storeState?: boolean;
27
- script?: string;
28
- scriptRef?: string;
29
- }
30
-
31
- export interface DAppTransactionInput {
32
- coinId: string;
33
- address?: string;
34
- amount?: string;
35
- tokenId?: string;
36
- }
37
-
38
- export interface DAppSwapParams {
39
- fromTokenId: string;
40
- toTokenId: string;
41
- amountIn: string;
42
- minAmountOut: string;
43
- slippageBps?: number;
44
- poolAddress?: string;
45
- }
46
-
47
- export interface DAppLiquidityParams {
48
- poolAddress: string;
49
- tokenAId: string;
50
- tokenBId: string;
51
- amountA?: string;
52
- amountB?: string;
53
- lpTokenAmount?: string;
54
- }
55
-
56
- export interface DAppMultisigParams {
57
- requiredSignatures: number;
58
- publicKeys: string[];
59
- timeoutBlocks?: number;
60
- }
61
-
62
- export interface DAppTimelockParams {
63
- releaseBlock: number;
64
- fallbackAddress?: string;
65
- }
66
-
67
- export interface DAppHtlcParams {
68
- hashlock: string;
69
- timeoutBlocks: number;
70
- recipientAddress: string;
71
- refundAddress: string;
72
- }
73
-
74
- export interface DAppContractCallParams {
75
- contractAddress: string;
76
- method?: string;
77
- args?: Record<string, string>;
78
- script?: string;
79
- }
80
-
81
- export interface TotemSendTransactionRequest {
82
- version: typeof TOTEM_SEND_TRANSACTION_VERSION;
83
- intent: DAppTransactionIntent;
84
- outputs: DAppTransactionOutput[];
85
- inputs?: DAppTransactionInput[];
86
- burn?: string;
87
- memo?: string;
88
- metadata?: {
89
- appName?: string;
90
- description?: string;
91
- iconUrl?: string;
92
- };
93
- options?: {
94
- verifyWithTotemidea?: boolean;
95
- skipPreview?: boolean;
96
- useSourceAddress?: string;
97
- excludeAddresses?: string[];
98
- };
99
- swap?: DAppSwapParams;
100
- liquidity?: DAppLiquidityParams;
101
- multisig?: DAppMultisigParams;
102
- timelock?: DAppTimelockParams;
103
- htlc?: DAppHtlcParams;
104
- contract?: DAppContractCallParams;
105
- }
106
-
107
- export interface TotemSendTransactionResponse {
108
- success: boolean;
109
- txpowid?: string;
110
- status?: 'pending' | 'submitted' | 'confirmed' | 'rejected';
111
- artifactId?: string;
112
- digestHex?: string;
113
- error?: string;
114
- errorCode?: TotemTransactionErrorCode;
115
- verification?: {
116
- totemideaValid?: boolean;
117
- totemideaWarnings?: string[];
118
- totemideaNotes?: string[];
119
- };
120
- }
121
-
122
- export type TotemTransactionErrorCode =
123
- | 'INVALID_REQUEST'
124
- | 'INSUFFICIENT_FUNDS'
125
- | 'PERMISSION_DENIED'
126
- | 'USER_REJECTED'
127
- | 'SITE_NOT_CONNECTED'
128
- | 'SPENDING_LIMIT_EXCEEDED'
129
- | 'TOKEN_NOT_ALLOWED'
130
- | 'VERIFICATION_FAILED'
131
- | 'BUILD_FAILED'
132
- | 'SIGN_FAILED'
133
- | 'BROADCAST_FAILED'
134
- | 'TIMEOUT';
135
-
136
- export interface SiteTransactionPermission {
137
- origin: string;
138
- grantedAt: number;
139
- expiresAt: number;
140
- scopes: TransactionScope[];
141
- }
142
-
143
- export interface TransactionScope {
144
- tokenId: string;
145
- tokenSymbol?: string;
146
- maxAmountPerTx: string;
147
- maxDailyAmount: string;
148
- dailyUsed: string;
149
- lastResetDate: string;
150
- allowedIntents: DAppTransactionIntent[];
151
- }
152
-
153
- export function validateSendTransactionRequest(request: unknown): { valid: boolean; errors: string[] } {
154
- const errors: string[] = [];
155
-
156
- if (!request || typeof request !== 'object') {
157
- return { valid: false, errors: ['Request must be an object'] };
158
- }
159
-
160
- const req = request as Record<string, unknown>;
161
-
162
- if (req.version !== TOTEM_SEND_TRANSACTION_VERSION) {
163
- errors.push(`Invalid version: expected ${TOTEM_SEND_TRANSACTION_VERSION}, got ${req.version}`);
164
- }
165
-
166
- const validIntents: DAppTransactionIntent[] = [
167
- 'send', 'token_send', 'swap', 'liquidity_add', 'liquidity_remove',
168
- 'contract_call', 'multisig', 'timelock', 'htlc', 'custom'
169
- ];
170
- if (!validIntents.includes(req.intent as DAppTransactionIntent)) {
171
- errors.push(`Invalid intent: ${req.intent}. Must be one of: ${validIntents.join(', ')}`);
172
- }
173
-
174
- if (!Array.isArray(req.outputs) || req.outputs.length === 0) {
175
- errors.push('outputs must be a non-empty array');
176
- } else {
177
- for (let i = 0; i < req.outputs.length; i++) {
178
- const output = req.outputs[i] as Record<string, unknown>;
179
- if (!output.address || typeof output.address !== 'string') {
180
- errors.push(`outputs[${i}].address is required and must be a string`);
181
- }
182
- if (!output.amount || typeof output.amount !== 'string') {
183
- errors.push(`outputs[${i}].amount is required and must be a string`);
184
- }
185
- const amountNum = parseFloat(output.amount as string);
186
- if (isNaN(amountNum) || amountNum <= 0) {
187
- errors.push(`outputs[${i}].amount must be a positive number`);
188
- }
189
- }
190
- }
191
-
192
- if (req.burn !== undefined) {
193
- const burnNum = parseFloat(req.burn as string);
194
- if (isNaN(burnNum) || burnNum < 0) {
195
- errors.push('burn must be a non-negative number string');
196
- }
197
- }
198
-
199
- if (req.intent === 'swap' && !req.swap) {
200
- errors.push('swap params required for swap intent');
201
- }
202
-
203
- if ((req.intent === 'liquidity_add' || req.intent === 'liquidity_remove') && !req.liquidity) {
204
- errors.push('liquidity params required for liquidity intent');
205
- }
206
-
207
- if (req.intent === 'multisig' && !req.multisig) {
208
- errors.push('multisig params required for multisig intent');
209
- }
210
-
211
- if (req.intent === 'timelock' && !req.timelock) {
212
- errors.push('timelock params required for timelock intent');
213
- }
214
-
215
- if (req.intent === 'htlc' && !req.htlc) {
216
- errors.push('htlc params required for htlc intent');
217
- }
218
-
219
- if (req.intent === 'contract_call' && !req.contract) {
220
- errors.push('contract params required for contract_call intent');
221
- }
222
-
223
- return { valid: errors.length === 0, errors };
224
- }
225
-
226
- export function simpleTotemSendRequest(
227
- to: string,
228
- amount: string,
229
- tokenId?: string
230
- ): TotemSendTransactionRequest {
231
- return {
232
- version: TOTEM_SEND_TRANSACTION_VERSION,
233
- intent: tokenId && tokenId !== '0x00' ? 'token_send' : 'send',
234
- outputs: [{
235
- address: to,
236
- amount,
237
- tokenId: tokenId || '0x00'
238
- }]
239
- };
240
- }
@@ -1,22 +0,0 @@
1
- export * from './types.js';
2
- export * from './dapp-types.js';
3
- export {
4
- encodeMiniNumber,
5
- encodeMiniData,
6
- encodeMiniString,
7
- serializeMMRProofChunk,
8
- serializeScriptProofWithProof,
9
- STATETYPE_HEX,
10
- STATETYPE_NUMBER,
11
- STATETYPE_STRING,
12
- STATETYPE_BOOL,
13
- encodeStateValue,
14
- serializeStateVariables,
15
- buildScriptProofFromDescriptor,
16
- deduplicateScriptDescriptors,
17
- serializeExtraScripts,
18
- aggregateSignatures,
19
- validateExternalSignature,
20
- computeScriptAddress,
21
- } from './witness-serializer.js';
22
- export * from './contract-helpers.js';
@@ -1,81 +0,0 @@
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;
@@ -1,145 +0,0 @@
1
- function kissHex(hex) {
2
- const raw = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
3
- return '0x' + raw.toUpperCase();
4
- }
5
- export function convertFlatChunkToSDK(chunk) {
6
- return {
7
- isLeft: chunk.isLeft,
8
- mmrData: { data: chunk.data, value: 0n }
9
- };
10
- }
11
- export function convertLegacyProofToSDK(legacy) {
12
- return {
13
- proof: {
14
- chunks: legacy.proofChain.map(convertFlatChunkToSDK)
15
- },
16
- blockTime: legacy.blockTime
17
- };
18
- }
19
- export function createEmptyMMRProof() {
20
- return { chunks: [] };
21
- }
22
- export function createSignedByDescriptor(address, wotsRootPublicKey) {
23
- return {
24
- address,
25
- scriptType: 'signedby',
26
- script: `RETURN SIGNEDBY(${kissHex(wotsRootPublicKey)})`,
27
- wotsRootPublicKey,
28
- mastProof: createEmptyMMRProof(),
29
- storeState: false
30
- };
31
- }
32
- export function createMultisigDescriptor(address, publicKey1, publicKey2, ownPublicKey) {
33
- return {
34
- address,
35
- scriptType: 'multisig',
36
- script: `RETURN SIGNEDBY(${kissHex(publicKey1)}) AND SIGNEDBY(${kissHex(publicKey2)})`,
37
- wotsRootPublicKey: ownPublicKey,
38
- multisigKeys: [publicKey1, publicKey2],
39
- multisigThreshold: 2,
40
- mastProof: createEmptyMMRProof(),
41
- storeState: false
42
- };
43
- }
44
- export function createMofNMultisigDescriptor(address, threshold, publicKeys, ownPublicKey) {
45
- const formattedKeys = publicKeys.map(pk => kissHex(pk)).join(' ');
46
- return {
47
- address,
48
- scriptType: 'multisig_mofn',
49
- script: `RETURN MULTISIG(${threshold} ${formattedKeys})`,
50
- wotsRootPublicKey: ownPublicKey,
51
- multisigKeys: publicKeys,
52
- multisigThreshold: threshold,
53
- mastProof: createEmptyMMRProof(),
54
- storeState: false
55
- };
56
- }
57
- export function createTimelockDescriptor(address, publicKey, unlockBlock) {
58
- return {
59
- address,
60
- scriptType: 'timelock',
61
- script: `RETURN SIGNEDBY(${kissHex(publicKey)}) AND @BLOCK GT ${unlockBlock}`,
62
- wotsRootPublicKey: publicKey,
63
- timelockBlock: unlockBlock,
64
- mastProof: createEmptyMMRProof(),
65
- storeState: false
66
- };
67
- }
68
- export function createHTLCDescriptor(address, ownerPublicKey, recipientPublicKey, hashLock, timeoutBlock, isOwner, preimage) {
69
- 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)})`;
70
- const descriptor = {
71
- address,
72
- scriptType: 'htlc',
73
- script,
74
- wotsRootPublicKey: isOwner ? ownerPublicKey : recipientPublicKey,
75
- htlcHash: hashLock,
76
- timelockBlock: timeoutBlock,
77
- mastProof: createEmptyMMRProof(),
78
- storeState: false
79
- };
80
- if (preimage) {
81
- descriptor.htlcPreimage = preimage;
82
- descriptor.stateVariables = [{ port: 1, value: preimage, type: 'string' }];
83
- }
84
- return descriptor;
85
- }
86
- export function createMASTDescriptor(address, rootHash, branchScript, branchProof, wotsPublicKey) {
87
- return {
88
- address,
89
- scriptType: 'mast',
90
- script: `MAST ${kissHex(rootHash)}`,
91
- wotsRootPublicKey: wotsPublicKey,
92
- extraScripts: new Map([[branchScript, branchProof]]),
93
- mastProof: createEmptyMMRProof(),
94
- storeState: false
95
- };
96
- }
97
- export function createExchangeDescriptor(address, ownerPublicKey, desiredAddress, desiredAmount, desiredTokenId) {
98
- const ownerPk = kissHex(ownerPublicKey);
99
- const script = `IF SIGNEDBY(PREVSTATE(0)) THEN RETURN TRUE ENDIF ASSERT VERIFYOUT(@INPUT PREVSTATE(1) PREVSTATE(2) PREVSTATE(3) TRUE) RETURN TRUE`;
100
- return {
101
- address,
102
- scriptType: 'exchange',
103
- script,
104
- wotsRootPublicKey: ownerPublicKey,
105
- stateVariables: [
106
- { port: 0, value: ownerPk, type: 'hex' },
107
- { port: 1, value: desiredAddress, type: 'hex' },
108
- { port: 2, value: desiredAmount, type: 'number' },
109
- { port: 3, value: desiredTokenId, type: 'hex' }
110
- ],
111
- verifyOutExpectations: [{
112
- inputIndex: '@INPUT',
113
- outputAddress: desiredAddress,
114
- amount: desiredAmount,
115
- tokenId: desiredTokenId,
116
- keepState: true
117
- }],
118
- mastProof: createEmptyMMRProof(),
119
- storeState: true
120
- };
121
- }
122
- export function createFlashCashDescriptor(address, ownerPublicKey, interestMultiplier = '1.01') {
123
- const script = `IF SIGNEDBY(PREVSTATE(1)) THEN RETURN TRUE ENDIF ASSERT SAMESTATE(1 1) RETURN VERIFYOUT(@INPUT @ADDRESS @AMOUNT*${interestMultiplier} @TOKENID TRUE)`;
124
- return {
125
- address,
126
- scriptType: 'flashcash',
127
- script,
128
- wotsRootPublicKey: ownerPublicKey,
129
- stateVariables: [{ port: 1, value: ownerPublicKey, type: 'hex' }],
130
- mastProof: createEmptyMMRProof(),
131
- storeState: true
132
- };
133
- }
134
- export function createSlowCashDescriptor(address, ownerPublicKey, withdrawalPercent = '0.9', cooldownBlocks = 10000n) {
135
- const script = `IF @COINAGE LT ${cooldownBlocks} THEN RETURN FALSE ENDIF ASSERT SIGNEDBY(${kissHex(ownerPublicKey)}) AND VERIFYOUT(@INPUT @ADDRESS @AMOUNT*${withdrawalPercent} @TOKENID TRUE)`;
136
- return {
137
- address,
138
- scriptType: 'slowcash',
139
- script,
140
- wotsRootPublicKey: ownerPublicKey,
141
- timelockBlock: cooldownBlocks,
142
- mastProof: createEmptyMMRProof(),
143
- storeState: false
144
- };
145
- }