@totemsdk/core 1.0.8 → 1.0.10

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 (142) 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.js +94 -64
  39. package/package.json +35 -6
  40. package/src/Streamable.d.ts +0 -265
  41. package/src/Streamable.js +0 -431
  42. package/src/Streamable.ts +0 -567
  43. package/src/__tests__/Streamable.parity.test.ts +0 -422
  44. package/src/__tests__/perAddressDerivation.parity.test.ts +0 -152
  45. package/src/__tests__/roottree-prepare.test.ts +0 -101
  46. package/src/__tests__/wots-parity.test.ts +0 -289
  47. package/src/adapters/index.d.ts +0 -190
  48. package/src/adapters/index.js +0 -117
  49. package/src/adapters/index.ts +0 -301
  50. package/src/adapters/types.ts +0 -235
  51. package/src/addr.oracle.test.ts +0 -25
  52. package/src/address.test.ts +0 -55
  53. package/src/binio.ts +0 -21
  54. package/src/bip39.d.ts +0 -91
  55. package/src/bip39.js +0 -427
  56. package/src/bip39.ts +0 -432
  57. package/src/derive.d.ts +0 -2
  58. package/src/derive.js +0 -13
  59. package/src/derive.ts +0 -11
  60. package/src/index.d.ts +0 -26
  61. package/src/index.js +0 -128
  62. package/src/index.test.ts +0 -5
  63. package/src/index.ts +0 -221
  64. package/src/javaStreamables.d.ts +0 -233
  65. package/src/javaStreamables.js +0 -328
  66. package/src/javaStreamables.ts +0 -403
  67. package/src/lease/LeaseMonitor.d.ts +0 -44
  68. package/src/lease/LeaseMonitor.js +0 -111
  69. package/src/lease/LeaseMonitor.ts +0 -157
  70. package/src/lease/LeaseStore.d.ts +0 -57
  71. package/src/lease/LeaseStore.js +0 -148
  72. package/src/lease/LeaseStore.ts +0 -203
  73. package/src/lease/WatermarkStore.d.ts +0 -61
  74. package/src/lease/WatermarkStore.js +0 -206
  75. package/src/lease/WatermarkStore.ts +0 -270
  76. package/src/lease/index.d.ts +0 -14
  77. package/src/lease/index.js +0 -22
  78. package/src/lease/index.ts +0 -41
  79. package/src/lease-client.d.ts +0 -31
  80. package/src/lease-client.js +0 -44
  81. package/src/lease-client.ts +0 -69
  82. package/src/minima32.d.ts +0 -10
  83. package/src/minima32.js +0 -113
  84. package/src/minima32.test.ts +0 -11
  85. package/src/minima32.ts +0 -127
  86. package/src/minimaWireSerializer.d.ts +0 -189
  87. package/src/minimaWireSerializer.js +0 -311
  88. package/src/minimaWireSerializer.test.ts +0 -466
  89. package/src/minimaWireSerializer.ts +0 -117
  90. package/src/mmr.d.ts +0 -159
  91. package/src/mmr.js +0 -352
  92. package/src/mmr.oracle.test.ts +0 -28
  93. package/src/mmr.ts +0 -429
  94. package/src/mx.test.ts +0 -25
  95. package/src/mx.ts +0 -1
  96. package/src/params.d.ts +0 -29
  97. package/src/params.d.ts.map +0 -1
  98. package/src/params.js +0 -20
  99. package/src/params.js.map +0 -1
  100. package/src/params.ts +0 -44
  101. package/src/script.d.ts +0 -7
  102. package/src/script.js +0 -27
  103. package/src/script.ts +0 -24
  104. package/src/scripts/contract-helpers.ts +0 -609
  105. package/src/scripts/dapp-types.ts +0 -240
  106. package/src/scripts/index.ts +0 -22
  107. package/src/scripts/types.ts +0 -247
  108. package/src/scripts/witness-serializer.ts +0 -384
  109. package/src/transaction.ts +0 -430
  110. package/src/treekey.d.ts +0 -383
  111. package/src/treekey.js +0 -774
  112. package/src/treekey.parity.test.ts +0 -459
  113. package/src/treekey.ts +0 -975
  114. package/src/tx/TransactionLifecycle.d.ts +0 -55
  115. package/src/tx/TransactionLifecycle.js +0 -188
  116. package/src/tx/TransactionLifecycle.ts +0 -280
  117. package/src/tx/TransactionReceiptStore.d.ts +0 -36
  118. package/src/tx/TransactionReceiptStore.js +0 -89
  119. package/src/tx/TransactionReceiptStore.ts +0 -112
  120. package/src/tx/TransactionService.d.ts +0 -31
  121. package/src/tx/TransactionService.js +0 -140
  122. package/src/tx/TransactionService.ts +0 -252
  123. package/src/tx/index.d.ts +0 -13
  124. package/src/tx/index.js +0 -20
  125. package/src/tx/index.ts +0 -44
  126. package/src/tx/types.d.ts +0 -80
  127. package/src/tx/types.js +0 -6
  128. package/src/tx/types.ts +0 -130
  129. package/src/util.d.ts +0 -1
  130. package/src/util.js +0 -5
  131. package/src/util.ts +0 -1
  132. package/src/utils.d.ts +0 -8
  133. package/src/utils.js +0 -42
  134. package/src/utils.ts +0 -38
  135. package/src/verify.ts +0 -210
  136. package/src/version.ts +0 -13
  137. package/src/wots.d.ts +0 -224
  138. package/src/wots.d.ts.map +0 -1
  139. package/src/wots.js +0 -565
  140. package/src/wots.js.map +0 -1
  141. package/src/wots.ts +0 -651
  142. 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,247 +0,0 @@
1
- import type { MMRData, MMRProofChunk, MMRProof } from '../mmr.js';
2
- export type { MMRProof };
3
-
4
- function kissHex(hex: string): string {
5
- const raw = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
6
- return '0x' + raw.toUpperCase();
7
- }
8
-
9
- export type StateVariableType = 'STATE' | 'PREVSTATE' | 'SAMESTATE';
10
-
11
- export interface StateValue {
12
- port: number;
13
- value: string | bigint | Uint8Array | boolean;
14
- type: 'bool' | 'number' | 'hex' | 'string';
15
- }
16
-
17
- export interface VerifyOutExpectation {
18
- inputIndex: number | '@INPUT';
19
- outputAddress: string;
20
- amount: string | bigint;
21
- tokenId: string;
22
- keepState: boolean;
23
- }
24
-
25
- export type ScriptType =
26
- | 'signedby'
27
- | 'multisig'
28
- | 'multisig_mofn'
29
- | 'timelock'
30
- | 'htlc'
31
- | 'mast'
32
- | 'exchange'
33
- | 'vault'
34
- | 'flashcash'
35
- | 'slowcash'
36
- | 'stateful'
37
- | 'custom';
38
-
39
- export interface ScriptDescriptor {
40
- address: string;
41
- scriptType: ScriptType;
42
- script: string;
43
- wotsRootPublicKey?: string;
44
- mastProof?: MMRProof;
45
- extraScripts?: Map<string, string>;
46
- stateVariables?: StateValue[];
47
- storeState?: boolean;
48
- verifyOutExpectations?: VerifyOutExpectation[];
49
- timelockBlock?: bigint;
50
- htlcHash?: string;
51
- htlcPreimage?: string;
52
- multisigKeys?: string[];
53
- multisigThreshold?: number;
54
- externalSignatures?: ExternalSignature[];
55
- }
56
-
57
- export interface ExternalSignature {
58
- publicKey: string;
59
- signature: string;
60
- proof?: MMRProof;
61
- signatureType: 'wots' | 'standard';
62
- validated?: boolean;
63
- }
64
-
65
- export interface ScriptCatalogEntry {
66
- address: string;
67
- script: string;
68
- scriptType: ScriptType;
69
- createdAt: number;
70
- lastUsed: number;
71
- }
72
-
73
- export interface ScriptProofResult {
74
- script: string;
75
- proof: MMRProof;
76
- serialized: Uint8Array;
77
- }
78
-
79
- export interface TransactionRoundState {
80
- round: number;
81
- previousRound: number;
82
- preservedPorts: number[];
83
- newStates: StateValue[];
84
- }
85
-
86
- export interface FlatMMRProofChunk {
87
- isLeft: boolean;
88
- data: Uint8Array;
89
- }
90
-
91
- export interface LegacyMMRProof {
92
- blockTime: bigint;
93
- proofChain: FlatMMRProofChunk[];
94
- }
95
-
96
- export function convertFlatChunkToSDK(chunk: FlatMMRProofChunk): MMRProofChunk {
97
- return {
98
- isLeft: chunk.isLeft,
99
- mmrData: { data: chunk.data, value: 0n }
100
- };
101
- }
102
-
103
- export function convertLegacyProofToSDK(legacy: LegacyMMRProof): { proof: MMRProof; blockTime: bigint } {
104
- return {
105
- proof: {
106
- chunks: legacy.proofChain.map(convertFlatChunkToSDK)
107
- },
108
- blockTime: legacy.blockTime
109
- };
110
- }
111
-
112
- export function createEmptyMMRProof(): MMRProof {
113
- return { chunks: [] };
114
- }
115
-
116
- export function createSignedByDescriptor(address: string, wotsRootPublicKey: string): ScriptDescriptor {
117
- return {
118
- address,
119
- scriptType: 'signedby',
120
- script: `RETURN SIGNEDBY(${kissHex(wotsRootPublicKey)})`,
121
- wotsRootPublicKey,
122
- mastProof: createEmptyMMRProof(),
123
- storeState: false
124
- };
125
- }
126
-
127
- export function createMultisigDescriptor(address: string, publicKey1: string, publicKey2: string, ownPublicKey: string): ScriptDescriptor {
128
- return {
129
- address,
130
- scriptType: 'multisig',
131
- script: `RETURN SIGNEDBY(${kissHex(publicKey1)}) AND SIGNEDBY(${kissHex(publicKey2)})`,
132
- wotsRootPublicKey: ownPublicKey,
133
- multisigKeys: [publicKey1, publicKey2],
134
- multisigThreshold: 2,
135
- mastProof: createEmptyMMRProof(),
136
- storeState: false
137
- };
138
- }
139
-
140
- export function createMofNMultisigDescriptor(address: string, threshold: number, publicKeys: string[], ownPublicKey: string): ScriptDescriptor {
141
- const formattedKeys = publicKeys.map(pk => kissHex(pk)).join(' ');
142
- return {
143
- address,
144
- scriptType: 'multisig_mofn',
145
- script: `RETURN MULTISIG(${threshold} ${formattedKeys})`,
146
- wotsRootPublicKey: ownPublicKey,
147
- multisigKeys: publicKeys,
148
- multisigThreshold: threshold,
149
- mastProof: createEmptyMMRProof(),
150
- storeState: false
151
- };
152
- }
153
-
154
- export function createTimelockDescriptor(address: string, publicKey: string, unlockBlock: bigint): ScriptDescriptor {
155
- return {
156
- address,
157
- scriptType: 'timelock',
158
- script: `RETURN SIGNEDBY(${kissHex(publicKey)}) AND @BLOCK GT ${unlockBlock}`,
159
- wotsRootPublicKey: publicKey,
160
- timelockBlock: unlockBlock,
161
- mastProof: createEmptyMMRProof(),
162
- storeState: false
163
- };
164
- }
165
-
166
- export function createHTLCDescriptor(address: string, ownerPublicKey: string, recipientPublicKey: string, hashLock: string, timeoutBlock: bigint, isOwner: boolean, preimage?: string): ScriptDescriptor {
167
- 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)})`;
168
- const descriptor: ScriptDescriptor = {
169
- address,
170
- scriptType: 'htlc',
171
- script,
172
- wotsRootPublicKey: isOwner ? ownerPublicKey : recipientPublicKey,
173
- htlcHash: hashLock,
174
- timelockBlock: timeoutBlock,
175
- mastProof: createEmptyMMRProof(),
176
- storeState: false
177
- };
178
- if (preimage) {
179
- descriptor.htlcPreimage = preimage;
180
- descriptor.stateVariables = [{ port: 1, value: preimage, type: 'string' }];
181
- }
182
- return descriptor;
183
- }
184
-
185
- export function createMASTDescriptor(address: string, rootHash: string, branchScript: string, branchProof: string, wotsPublicKey?: string): ScriptDescriptor {
186
- return {
187
- address,
188
- scriptType: 'mast',
189
- script: `MAST ${kissHex(rootHash)}`,
190
- wotsRootPublicKey: wotsPublicKey,
191
- extraScripts: new Map([[branchScript, branchProof]]),
192
- mastProof: createEmptyMMRProof(),
193
- storeState: false
194
- };
195
- }
196
-
197
- export function createExchangeDescriptor(address: string, ownerPublicKey: string, desiredAddress: string, desiredAmount: string, desiredTokenId: string): ScriptDescriptor {
198
- const ownerPk = kissHex(ownerPublicKey);
199
- const script = `IF SIGNEDBY(PREVSTATE(0)) THEN RETURN TRUE ENDIF ASSERT VERIFYOUT(@INPUT PREVSTATE(1) PREVSTATE(2) PREVSTATE(3) TRUE) RETURN TRUE`;
200
- return {
201
- address,
202
- scriptType: 'exchange',
203
- script,
204
- wotsRootPublicKey: ownerPublicKey,
205
- stateVariables: [
206
- { port: 0, value: ownerPk, type: 'hex' },
207
- { port: 1, value: desiredAddress, type: 'hex' },
208
- { port: 2, value: desiredAmount, type: 'number' },
209
- { port: 3, value: desiredTokenId, type: 'hex' }
210
- ],
211
- verifyOutExpectations: [{
212
- inputIndex: '@INPUT',
213
- outputAddress: desiredAddress,
214
- amount: desiredAmount,
215
- tokenId: desiredTokenId,
216
- keepState: true
217
- }],
218
- mastProof: createEmptyMMRProof(),
219
- storeState: true
220
- };
221
- }
222
-
223
- export function createFlashCashDescriptor(address: string, ownerPublicKey: string, interestMultiplier: string = '1.01'): ScriptDescriptor {
224
- const script = `IF SIGNEDBY(PREVSTATE(1)) THEN RETURN TRUE ENDIF ASSERT SAMESTATE(1 1) RETURN VERIFYOUT(@INPUT @ADDRESS @AMOUNT*${interestMultiplier} @TOKENID TRUE)`;
225
- return {
226
- address,
227
- scriptType: 'flashcash',
228
- script,
229
- wotsRootPublicKey: ownerPublicKey,
230
- stateVariables: [{ port: 1, value: ownerPublicKey, type: 'hex' }],
231
- mastProof: createEmptyMMRProof(),
232
- storeState: true
233
- };
234
- }
235
-
236
- export function createSlowCashDescriptor(address: string, ownerPublicKey: string, withdrawalPercent: string = '0.9', cooldownBlocks: bigint = 10000n): ScriptDescriptor {
237
- const script = `IF @COINAGE LT ${cooldownBlocks} THEN RETURN FALSE ENDIF ASSERT SIGNEDBY(${kissHex(ownerPublicKey)}) AND VERIFYOUT(@INPUT @ADDRESS @AMOUNT*${withdrawalPercent} @TOKENID TRUE)`;
238
- return {
239
- address,
240
- scriptType: 'slowcash',
241
- script,
242
- wotsRootPublicKey: ownerPublicKey,
243
- timelockBlock: cooldownBlocks,
244
- mastProof: createEmptyMMRProof(),
245
- storeState: false
246
- };
247
- }