@arkade-os/sdk 0.5.0-rc.11 → 0.5.0-rc.13

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 (94) hide show
  1. package/README.md +43 -12
  2. package/dist/adapters/expo.cjs +5 -5
  3. package/dist/adapters/expo.d.cts +2 -2
  4. package/dist/adapters/expo.d.ts +2 -2
  5. package/dist/adapters/expo.js +3 -3
  6. package/dist/{asyncStorageTaskQueue-DBaZsltv.d.cts → asyncStorageTaskQueue-0EeSeCAt.d.cts} +1 -1
  7. package/dist/{asyncStorageTaskQueue-uAG3XLyg.d.ts → asyncStorageTaskQueue-DV94jhwq.d.ts} +1 -1
  8. package/dist/{chunk-WSQAWSEH.js → chunk-3JLYJ5KZ.js} +75 -237
  9. package/dist/chunk-3JLYJ5KZ.js.map +1 -0
  10. package/dist/{chunk-VMLLYEYM.js → chunk-4EU2Q6YT.js} +12 -14
  11. package/dist/chunk-4EU2Q6YT.js.map +1 -0
  12. package/dist/{chunk-IA32YGLH.cjs → chunk-7BACS4XK.cjs} +10 -10
  13. package/dist/chunk-7BACS4XK.cjs.map +1 -0
  14. package/dist/{chunk-5OBGYL6U.cjs → chunk-7NK6XFC3.cjs} +120 -194
  15. package/dist/chunk-7NK6XFC3.cjs.map +1 -0
  16. package/dist/{chunk-CQPQ7D4U.cjs → chunk-BFQX2KS3.cjs} +87 -248
  17. package/dist/chunk-BFQX2KS3.cjs.map +1 -0
  18. package/dist/{chunk-DD6MTNAS.js → chunk-D7JLTHSZ.js} +5 -5
  19. package/dist/chunk-D7JLTHSZ.js.map +1 -0
  20. package/dist/{chunk-CMLSTGOC.js → chunk-EJYWGTZ7.js} +119 -194
  21. package/dist/chunk-EJYWGTZ7.js.map +1 -0
  22. package/dist/{chunk-T2ILYGWE.cjs → chunk-FDQQOF3F.cjs} +327 -1080
  23. package/dist/chunk-FDQQOF3F.cjs.map +1 -0
  24. package/dist/{chunk-MGDXN74N.cjs → chunk-I4YBVHAK.cjs} +2357 -3374
  25. package/dist/chunk-I4YBVHAK.cjs.map +1 -0
  26. package/dist/{chunk-M2ZUPLKQ.js → chunk-IV2252XM.js} +1946 -2977
  27. package/dist/chunk-IV2252XM.js.map +1 -0
  28. package/dist/{chunk-OMJRW2D5.js → chunk-JOUPIZ32.js} +263 -1036
  29. package/dist/chunk-JOUPIZ32.js.map +1 -0
  30. package/dist/{chunk-PWEBQNIE.cjs → chunk-RDQSVIXD.cjs} +22 -24
  31. package/dist/chunk-RDQSVIXD.cjs.map +1 -0
  32. package/dist/contracts/handlers/index.cjs +9 -9
  33. package/dist/contracts/handlers/index.d.cts +3 -3
  34. package/dist/contracts/handlers/index.d.ts +3 -3
  35. package/dist/contracts/handlers/index.js +2 -2
  36. package/dist/{delegate-DFwlkVYR.d.cts → delegate-BgpUJW5B.d.cts} +1 -1
  37. package/dist/{delegate-D3YHDERL.d.ts → delegate-BuagcGnG.d.ts} +1 -1
  38. package/dist/{index-DTvUv5lD.d.cts → index-CKmB14Yu.d.cts} +1145 -2263
  39. package/dist/{index-DTvUv5lD.d.ts → index-CKmB14Yu.d.ts} +1145 -2263
  40. package/dist/index-D0BuYwhF.d.cts +637 -0
  41. package/dist/index-DbzyrqK7.d.ts +637 -0
  42. package/dist/index.cjs +341 -297
  43. package/dist/index.d.cts +379 -788
  44. package/dist/index.d.ts +379 -788
  45. package/dist/index.js +4 -4
  46. package/dist/repositories/realm/index.cjs +142 -101
  47. package/dist/repositories/realm/index.cjs.map +1 -1
  48. package/dist/repositories/realm/index.d.cts +13 -11
  49. package/dist/repositories/realm/index.d.ts +13 -11
  50. package/dist/repositories/realm/index.js +130 -89
  51. package/dist/repositories/realm/index.js.map +1 -1
  52. package/dist/repositories/sqlite/index.cjs +158 -118
  53. package/dist/repositories/sqlite/index.cjs.map +1 -1
  54. package/dist/repositories/sqlite/index.d.cts +14 -13
  55. package/dist/repositories/sqlite/index.d.ts +14 -13
  56. package/dist/repositories/sqlite/index.js +147 -107
  57. package/dist/repositories/sqlite/index.js.map +1 -1
  58. package/dist/{taskRunner-B5bl0YRt.d.ts → taskRunner-BX-pB0sv.d.ts} +1 -1
  59. package/dist/{taskRunner--sKy9Inv.d.cts → taskRunner-DJrFFyus.d.cts} +1 -1
  60. package/dist/wallet/expo/background.cjs +14 -14
  61. package/dist/wallet/expo/background.cjs.map +1 -1
  62. package/dist/wallet/expo/background.d.cts +8 -14
  63. package/dist/wallet/expo/background.d.ts +8 -14
  64. package/dist/wallet/expo/background.js +6 -6
  65. package/dist/wallet/expo/background.js.map +1 -1
  66. package/dist/wallet/expo/index.cjs +14 -14
  67. package/dist/wallet/expo/index.cjs.map +1 -1
  68. package/dist/wallet/expo/index.d.cts +5 -5
  69. package/dist/wallet/expo/index.d.ts +5 -5
  70. package/dist/wallet/expo/index.js +5 -5
  71. package/dist/wallet/expo/index.js.map +1 -1
  72. package/dist/wallet-BsL2G3Qb.d.cts +1542 -0
  73. package/dist/wallet-DXNiCmq8.d.ts +1542 -0
  74. package/dist/worker/expo/index.cjs +9 -9
  75. package/dist/worker/expo/index.d.cts +4 -4
  76. package/dist/worker/expo/index.d.ts +4 -4
  77. package/dist/worker/expo/index.js +5 -5
  78. package/package.json +3 -2
  79. package/dist/chunk-5OBGYL6U.cjs.map +0 -1
  80. package/dist/chunk-CMLSTGOC.js.map +0 -1
  81. package/dist/chunk-CQPQ7D4U.cjs.map +0 -1
  82. package/dist/chunk-DD6MTNAS.js.map +0 -1
  83. package/dist/chunk-IA32YGLH.cjs.map +0 -1
  84. package/dist/chunk-M2ZUPLKQ.js.map +0 -1
  85. package/dist/chunk-MGDXN74N.cjs.map +0 -1
  86. package/dist/chunk-OMJRW2D5.js.map +0 -1
  87. package/dist/chunk-PWEBQNIE.cjs.map +0 -1
  88. package/dist/chunk-T2ILYGWE.cjs.map +0 -1
  89. package/dist/chunk-VMLLYEYM.js.map +0 -1
  90. package/dist/chunk-WSQAWSEH.js.map +0 -1
  91. package/dist/hdWalletCapable-C350s3bP.d.ts +0 -2206
  92. package/dist/hdWalletCapable-rrOmXcbT.d.cts +0 -2206
  93. package/dist/index-C0ZyGoyP.d.cts +0 -850
  94. package/dist/index-DASN1cVk.d.ts +0 -850
@@ -1,8 +1,8 @@
1
- import { serializeVtxo, isVtxoForScript, serializeUtxo, serializeAssets, scriptFromArkAddress, deserializeVtxo, deserializeUtxo, deserializeAssets, assertIntentIdUnique, intentMatchesFilter, intentPageBounds, isTerminalIntentState, mergeChainedTxType, legacyVtxoFacts } from '../../chunk-M2ZUPLKQ.js';
2
- export { ChainedTxType } from '../../chunk-M2ZUPLKQ.js';
3
- import '../../chunk-WSQAWSEH.js';
4
- import '../../chunk-OMJRW2D5.js';
5
- import '../../chunk-CMLSTGOC.js';
1
+ import { serializeVtxo, createdAtToIso, assertPageRequest, pageResult, checkSaveVtxosForScript, serializeUtxo, assertHistoryPageFilter, compareHistoryCursors, serializeAssets, scriptFromArkAddress, deserializeVtxo, deserializeUtxo, deserializeAssets, contractFilterMatchesNothing, assertIntentIdUnique, intentMatchesFilter, isTerminalIntentState, mergeChainedTxType, legacyVtxoFacts } from '../../chunk-IV2252XM.js';
2
+ export { ChainedTxType } from '../../chunk-IV2252XM.js';
3
+ import '../../chunk-3JLYJ5KZ.js';
4
+ import '../../chunk-JOUPIZ32.js';
5
+ import { isVtxoSpent } from '../../chunk-EJYWGTZ7.js';
6
6
 
7
7
  // src/repositories/realm/walletRepository.ts
8
8
  var RealmWalletRepository = class {
@@ -10,7 +10,7 @@ var RealmWalletRepository = class {
10
10
  this.realm = realm;
11
11
  }
12
12
  realm;
13
- version = 1;
13
+ version = 2;
14
14
  // ── Lifecycle ──────────────────────────────────────────────────────
15
15
  async ensureInit() {
16
16
  }
@@ -27,10 +27,8 @@ var RealmWalletRepository = class {
27
27
  });
28
28
  }
29
29
  // ── VTXO management ────────────────────────────────────────────────
30
- async getVtxos(address) {
31
- await this.ensureInit();
32
- const results = this.realm.objects("ArkVtxo").filtered("address == $0", address);
33
- return [...results].map(vtxoObjectToDomain);
30
+ async getVtxosPage(address, page) {
31
+ return this.pageByAddress("ArkVtxo", address, page, vtxoObjectToDomain);
34
32
  }
35
33
  async saveVtxos(address, vtxos) {
36
34
  await this.ensureInit();
@@ -51,13 +49,13 @@ var RealmWalletRepository = class {
51
49
  intentCb: s.intentTapLeafScript.cb,
52
50
  intentS: s.intentTapLeafScript.s,
53
51
  statusJson: JSON.stringify(s.status),
54
- createdAt: typeof s.createdAt === "string" ? s.createdAt : s.createdAt instanceof Date ? s.createdAt.toISOString() : new Date(s.createdAt).toISOString(),
52
+ createdAt: createdAtToIso(s.createdAt),
55
53
  isUnrolled: s.isUnrolled ?? false,
56
54
  isSpent: s.isSpent === void 0 ? null : s.isSpent,
57
55
  isSwept: s.isSwept === void 0 ? null : s.isSwept,
58
56
  isPreconfirmed: s.isPreconfirmed === void 0 ? null : s.isPreconfirmed,
59
57
  commitmentTxIdsJson: s.commitmentTxIds ? JSON.stringify(s.commitmentTxIds) : null,
60
- expiresAt: s.expiresAt === void 0 ? null : s.expiresAt instanceof Date ? s.expiresAt.toISOString() : new Date(s.expiresAt).toISOString(),
58
+ expiresAt: s.expiresAt === void 0 ? null : new Date(s.expiresAt).toISOString(),
61
59
  expiresAtHeight: s.expiresAtHeight ?? null,
62
60
  spentBy: s.spentBy ?? null,
63
61
  settledBy: s.settledBy ?? null,
@@ -72,42 +70,74 @@ var RealmWalletRepository = class {
72
70
  });
73
71
  }
74
72
  async deleteVtxos(address) {
75
- await this.ensureInit();
76
- this.realm.write(() => {
77
- const toDelete = this.realm.objects("ArkVtxo").filtered("address == $0", address);
78
- this.realm.delete(toDelete);
79
- });
73
+ return this.deleteWhere("ArkVtxo", "address", address);
80
74
  }
81
- async getVtxosForScript(script) {
75
+ async getVtxosForScriptPage(script, page, options) {
76
+ assertPageRequest(page);
82
77
  await this.ensureInit();
83
- const results = this.realm.objects("ArkVtxo").filtered("script == $0", script);
84
- return [...results].map(vtxoObjectToDomain);
85
- }
86
- async saveVtxosForScript(key, vtxos) {
87
- if (!key.address) {
88
- throw new Error("RealmWalletRepository requires an address");
78
+ let results = this.realm.objects("ArkVtxo").filtered("script == $0", script);
79
+ if (options?.unspentOnly) {
80
+ results = results.filtered(
81
+ "(isSpent == null OR isSpent == $0) AND (spentBy == null OR spentBy == $1) AND (settledBy == null OR settledBy == $1)",
82
+ false,
83
+ ""
84
+ );
89
85
  }
90
- for (const vtxo of vtxos) {
91
- if (!isVtxoForScript(vtxo, key.script)) {
92
- throw new Error(
93
- `VTXO ${vtxo.txid}:${vtxo.vout} script mismatch: expected ${key.script}, got ${vtxo.script}`
94
- );
95
- }
86
+ if (page.after) {
87
+ results = results.filtered(
88
+ "address > $0 OR (address == $0 AND (txid > $1 OR (txid == $1 AND vout > $2)))",
89
+ page.after.address,
90
+ page.after.txid,
91
+ page.after.vout
92
+ );
96
93
  }
97
- return this.saveVtxos(key.address, vtxos);
94
+ const rows = [];
95
+ for (const row of results.sorted([
96
+ ["address", false],
97
+ ["txid", false],
98
+ ["vout", false]
99
+ ])) {
100
+ rows.push({ address: row.address, vtxo: vtxoObjectToDomain(row) });
101
+ if (rows.length > page.limit) break;
102
+ }
103
+ const result = pageResult(rows, page.limit, (row) => ({
104
+ address: row.address,
105
+ txid: row.vtxo.txid,
106
+ vout: row.vtxo.vout
107
+ }));
108
+ return options?.unspentOnly ? { ...result, items: result.items.filter((row) => !isVtxoSpent(row.vtxo)) } : result;
109
+ }
110
+ async saveVtxosForScript(key, vtxos) {
111
+ return this.saveVtxos(checkSaveVtxosForScript("RealmWalletRepository", key, vtxos), vtxos);
98
112
  }
99
113
  async deleteVtxosForScript(script) {
100
- await this.ensureInit();
101
- this.realm.write(() => {
102
- const toDelete = this.realm.objects("ArkVtxo").filtered("script == $0", script);
103
- this.realm.delete(toDelete);
104
- });
114
+ return this.deleteWhere("ArkVtxo", "script", script);
105
115
  }
106
116
  // ── UTXO management ────────────────────────────────────────────────
107
- async getUtxos(address) {
117
+ async getUtxosPage(address, page) {
118
+ return this.pageByAddress("ArkUtxo", address, page, utxoObjectToDomain);
119
+ }
120
+ async pageByAddress(schema, address, page, deserialize) {
121
+ assertPageRequest(page);
108
122
  await this.ensureInit();
109
- const results = this.realm.objects("ArkUtxo").filtered("address == $0", address);
110
- return [...results].map(utxoObjectToDomain);
123
+ let results = this.realm.objects(schema).filtered("address == $0", address);
124
+ if (page.after) {
125
+ results = results.filtered(
126
+ "txid > $0 OR (txid == $0 AND vout > $1)",
127
+ page.after.txid,
128
+ page.after.vout
129
+ );
130
+ }
131
+ const rows = [];
132
+ for (const row of results.sorted([
133
+ ["txid", false],
134
+ ["vout", false]
135
+ ])) {
136
+ rows.push({ key: { txid: row.txid, vout: row.vout }, item: deserialize(row) });
137
+ if (rows.length > page.limit) break;
138
+ }
139
+ const result = pageResult(rows, page.limit, (row) => row.key);
140
+ return { items: result.items.map((row) => row.item), nextCursor: result.nextCursor };
111
141
  }
112
142
  async saveUtxos(address, utxos) {
113
143
  await this.ensureInit();
@@ -136,19 +166,31 @@ var RealmWalletRepository = class {
136
166
  });
137
167
  }
138
168
  async deleteUtxos(address) {
139
- await this.ensureInit();
140
- this.realm.write(() => {
141
- const toDelete = this.realm.objects("ArkUtxo").filtered("address == $0", address);
142
- this.realm.delete(toDelete);
143
- });
169
+ return this.deleteWhere("ArkUtxo", "address", address);
144
170
  }
145
171
  // ── Transaction history ────────────────────────────────────────────
146
- async getTransactionHistory(address) {
147
- await this.ensureInit();
148
- const results = this.realm.objects("ArkTransaction").filtered("address == $0", address);
149
- const txs = [...results].map(txObjectToDomain);
150
- txs.sort((a, b) => a.createdAt - b.createdAt);
151
- return txs;
172
+ async getTransactionHistoryPage(filter, page) {
173
+ assertPageRequest(page);
174
+ assertHistoryPageFilter(filter);
175
+ let results = this.realm.objects("ArkTransaction").filtered("address == $0", filter.address);
176
+ results = results.filtered(
177
+ "createdAt >= $0",
178
+ Math.max(filter.since ?? 0, page.after?.createdAt ?? 0)
179
+ );
180
+ const rows = [];
181
+ for (const row of results.sorted([
182
+ ["createdAt", false],
183
+ ["boardingTxid", false],
184
+ ["commitmentTxid", false],
185
+ ["arkTxid", false]
186
+ ])) {
187
+ const tx = txObjectToDomain(row);
188
+ if (page.after !== void 0 && compareHistoryCursors({ createdAt: tx.createdAt, key: tx.key }, page.after) <= 0)
189
+ continue;
190
+ rows.push(tx);
191
+ if (rows.length > page.limit) break;
192
+ }
193
+ return pageResult(rows, page.limit, (tx) => ({ createdAt: tx.createdAt, key: tx.key }));
152
194
  }
153
195
  async saveTransactions(address, txs) {
154
196
  await this.ensureInit();
@@ -174,9 +216,12 @@ var RealmWalletRepository = class {
174
216
  });
175
217
  }
176
218
  async deleteTransactions(address) {
219
+ return this.deleteWhere("ArkTransaction", "address", address);
220
+ }
221
+ async deleteWhere(objectType, field, value) {
177
222
  await this.ensureInit();
178
223
  this.realm.write(() => {
179
- const toDelete = this.realm.objects("ArkTransaction").filtered("address == $0", address);
224
+ const toDelete = this.realm.objects(objectType).filtered(`${field} == $0`, value);
180
225
  this.realm.delete(toDelete);
181
226
  });
182
227
  }
@@ -287,7 +332,7 @@ var RealmContractRepository = class {
287
332
  this.realm = realm;
288
333
  }
289
334
  realm;
290
- version = 2;
335
+ version = 3;
291
336
  // ── Lifecycle ──────────────────────────────────────────────────────
292
337
  async ensureInit() {
293
338
  }
@@ -301,41 +346,30 @@ var RealmContractRepository = class {
301
346
  });
302
347
  }
303
348
  // ── Contract management ────────────────────────────────────────────
304
- async getContracts(filter) {
305
- await this.ensureInit();
349
+ async getContractsPage(filter, page) {
350
+ assertPageRequest(page);
351
+ if (contractFilterMatchesNothing(filter)) return { items: [] };
306
352
  let results = this.realm.objects("ArkContract");
353
+ const parts = [];
354
+ const args = [];
355
+ let argIndex = 0;
307
356
  if (filter) {
308
- const filterParts = [];
309
- const filterArgs = [];
310
- let argIndex = 0;
311
- argIndex = this.addFilterCondition(
312
- filterParts,
313
- filterArgs,
314
- "script",
315
- filter.script,
316
- argIndex
317
- );
318
- argIndex = this.addFilterCondition(
319
- filterParts,
320
- filterArgs,
321
- "state",
322
- filter.state,
323
- argIndex
324
- );
325
- argIndex = this.addFilterCondition(
326
- filterParts,
327
- filterArgs,
328
- "type",
329
- filter.type,
330
- argIndex
331
- );
332
- argIndex = this.addWatchCondition(filterParts, filterArgs, filter.watch, argIndex);
333
- if (filterParts.length > 0) {
334
- const query = filterParts.join(" AND ");
335
- results = results.filtered(query, ...filterArgs);
336
- }
357
+ argIndex = this.addFilterCondition(parts, args, "script", filter.script, argIndex);
358
+ argIndex = this.addFilterCondition(parts, args, "state", filter.state, argIndex);
359
+ argIndex = this.addFilterCondition(parts, args, "type", filter.type, argIndex);
360
+ argIndex = this.addWatchCondition(parts, args, filter.watch, argIndex);
361
+ }
362
+ if (page.after !== void 0) {
363
+ parts.push(`script > $${argIndex}`);
364
+ args.push(page.after);
337
365
  }
338
- return [...results].map(contractObjectToDomain);
366
+ if (parts.length) results = results.filtered(parts.join(" AND "), ...args);
367
+ const rows = [];
368
+ for (const row of results.sorted("script")) {
369
+ rows.push(contractObjectToDomain(row));
370
+ if (rows.length > page.limit) break;
371
+ }
372
+ return pageResult(rows, page.limit, (contract) => contract.script);
339
373
  }
340
374
  async saveContract(contract) {
341
375
  await this.ensureInit();
@@ -483,11 +517,18 @@ var RealmIntentRepository = class {
483
517
  );
484
518
  });
485
519
  }
486
- async getIntents(filter) {
487
- const all = [...this.realm.objects("ArkIntent")].map(toIntent).sort((a, b) => a.createdAt - b.createdAt || a.intentTxId.localeCompare(b.intentTxId));
488
- const out = filter ? all.filter((i) => intentMatchesFilter(i, filter)) : all;
489
- const { skip, end } = intentPageBounds(filter, out.length);
490
- return out.slice(skip, end);
520
+ async getIntentsPage(filter, page) {
521
+ assertPageRequest(page);
522
+ let results = this.realm.objects("ArkIntent");
523
+ if (page.after !== void 0) results = results.filtered("intentTxId > $0", page.after);
524
+ const rows = [];
525
+ for (const row of results.sorted("intentTxId")) {
526
+ const intent = toIntent(row);
527
+ if (filter && !intentMatchesFilter(intent, filter)) continue;
528
+ rows.push(intent);
529
+ if (rows.length > page.limit) break;
530
+ }
531
+ return pageResult(rows, page.limit, (intent) => intent.intentTxId);
491
532
  }
492
533
  async getLockedVtxoOutpoints() {
493
534
  const out = [];