@arkade-os/sdk 0.2.3 → 0.3.0-alpha.1

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 (121) hide show
  1. package/README.md +114 -43
  2. package/dist/cjs/adapters/asyncStorage.js +5 -0
  3. package/dist/cjs/adapters/fileSystem.js +5 -0
  4. package/dist/cjs/adapters/indexedDB.js +5 -0
  5. package/dist/cjs/adapters/localStorage.js +5 -0
  6. package/dist/cjs/arknote/index.js +4 -4
  7. package/dist/cjs/bip322/index.js +11 -9
  8. package/dist/cjs/forfeit.js +2 -2
  9. package/dist/cjs/identity/index.js +15 -0
  10. package/dist/cjs/identity/singleKey.js +24 -5
  11. package/dist/cjs/index.js +7 -5
  12. package/dist/cjs/musig2/keys.js +7 -7
  13. package/dist/cjs/musig2/nonces.js +1 -1
  14. package/dist/cjs/musig2/sign.js +6 -6
  15. package/dist/cjs/networks.js +6 -6
  16. package/dist/cjs/repositories/contractRepository.js +130 -0
  17. package/dist/cjs/repositories/index.js +18 -0
  18. package/dist/cjs/repositories/walletRepository.js +136 -0
  19. package/dist/cjs/script/address.js +3 -3
  20. package/dist/cjs/script/base.js +7 -7
  21. package/dist/cjs/script/tapscript.js +21 -21
  22. package/dist/cjs/script/vhtlc.js +2 -2
  23. package/dist/cjs/storage/asyncStorage.js +47 -0
  24. package/dist/cjs/storage/fileSystem.js +138 -0
  25. package/dist/cjs/storage/inMemory.js +21 -0
  26. package/dist/cjs/storage/indexedDB.js +97 -0
  27. package/dist/cjs/storage/localStorage.js +48 -0
  28. package/dist/cjs/tree/signingSession.js +12 -11
  29. package/dist/cjs/tree/txTree.js +6 -6
  30. package/dist/cjs/tree/validation.js +5 -5
  31. package/dist/cjs/utils/arkTransaction.js +5 -5
  32. package/dist/cjs/utils/unknownFields.js +5 -5
  33. package/dist/cjs/wallet/onchain.js +16 -10
  34. package/dist/cjs/wallet/serviceWorker/request.js +4 -14
  35. package/dist/cjs/wallet/serviceWorker/response.js +0 -13
  36. package/dist/cjs/wallet/serviceWorker/wallet.js +124 -130
  37. package/dist/cjs/wallet/serviceWorker/worker.js +84 -53
  38. package/dist/cjs/wallet/unroll.js +6 -6
  39. package/dist/cjs/wallet/wallet.js +37 -20
  40. package/dist/esm/adapters/asyncStorage.js +1 -0
  41. package/dist/esm/adapters/fileSystem.js +1 -0
  42. package/dist/esm/adapters/indexedDB.js +1 -0
  43. package/dist/esm/adapters/localStorage.js +1 -0
  44. package/dist/esm/arknote/index.js +2 -2
  45. package/dist/esm/bip322/index.js +4 -2
  46. package/dist/esm/forfeit.js +1 -1
  47. package/dist/esm/identity/index.js +1 -1
  48. package/dist/esm/identity/singleKey.js +22 -3
  49. package/dist/esm/index.js +5 -4
  50. package/dist/esm/musig2/keys.js +7 -7
  51. package/dist/esm/musig2/nonces.js +1 -1
  52. package/dist/esm/musig2/sign.js +5 -5
  53. package/dist/esm/networks.js +1 -1
  54. package/dist/esm/repositories/contractRepository.js +126 -0
  55. package/dist/esm/repositories/index.js +2 -0
  56. package/dist/esm/repositories/walletRepository.js +132 -0
  57. package/dist/esm/script/address.js +1 -1
  58. package/dist/esm/script/base.js +3 -3
  59. package/dist/esm/script/tapscript.js +2 -2
  60. package/dist/esm/script/vhtlc.js +1 -1
  61. package/dist/esm/storage/asyncStorage.js +43 -0
  62. package/dist/esm/storage/fileSystem.js +101 -0
  63. package/dist/esm/storage/inMemory.js +17 -0
  64. package/dist/esm/storage/indexedDB.js +93 -0
  65. package/dist/esm/storage/localStorage.js +44 -0
  66. package/dist/esm/tree/signingSession.js +4 -3
  67. package/dist/esm/tree/txTree.js +2 -2
  68. package/dist/esm/tree/validation.js +2 -2
  69. package/dist/esm/utils/arkTransaction.js +2 -2
  70. package/dist/esm/utils/unknownFields.js +1 -1
  71. package/dist/esm/wallet/onchain.js +14 -8
  72. package/dist/esm/wallet/serviceWorker/request.js +4 -14
  73. package/dist/esm/wallet/serviceWorker/response.js +0 -13
  74. package/dist/esm/wallet/serviceWorker/wallet.js +125 -131
  75. package/dist/esm/wallet/serviceWorker/worker.js +85 -54
  76. package/dist/esm/wallet/unroll.js +2 -2
  77. package/dist/esm/wallet/wallet.js +25 -8
  78. package/dist/types/adapters/asyncStorage.d.ts +2 -0
  79. package/dist/types/adapters/fileSystem.d.ts +2 -0
  80. package/dist/types/adapters/indexedDB.d.ts +2 -0
  81. package/dist/types/adapters/localStorage.d.ts +2 -0
  82. package/dist/types/arknote/index.d.ts +1 -1
  83. package/dist/types/bip322/index.d.ts +2 -2
  84. package/dist/types/forfeit.d.ts +1 -1
  85. package/dist/types/identity/index.d.ts +4 -2
  86. package/dist/types/identity/singleKey.d.ts +13 -2
  87. package/dist/types/index.d.ts +5 -5
  88. package/dist/types/repositories/contractRepository.d.ts +20 -0
  89. package/dist/types/repositories/index.d.ts +2 -0
  90. package/dist/types/repositories/walletRepository.d.ts +38 -0
  91. package/dist/types/script/address.d.ts +1 -1
  92. package/dist/types/script/base.d.ts +1 -1
  93. package/dist/types/script/default.d.ts +1 -1
  94. package/dist/types/script/tapscript.d.ts +1 -1
  95. package/dist/types/script/vhtlc.d.ts +1 -1
  96. package/dist/types/storage/asyncStorage.d.ts +9 -0
  97. package/dist/types/storage/fileSystem.d.ts +11 -0
  98. package/dist/types/storage/inMemory.d.ts +8 -0
  99. package/dist/types/storage/index.d.ts +6 -0
  100. package/dist/types/storage/indexedDB.d.ts +12 -0
  101. package/dist/types/storage/localStorage.d.ts +8 -0
  102. package/dist/types/tree/txTree.d.ts +1 -1
  103. package/dist/types/tree/validation.d.ts +1 -1
  104. package/dist/types/utils/anchor.d.ts +1 -1
  105. package/dist/types/utils/arkTransaction.d.ts +3 -3
  106. package/dist/types/utils/unknownFields.d.ts +1 -1
  107. package/dist/types/wallet/index.d.ts +4 -1
  108. package/dist/types/wallet/onchain.d.ts +5 -4
  109. package/dist/types/wallet/serviceWorker/request.d.ts +1 -7
  110. package/dist/types/wallet/serviceWorker/response.d.ts +1 -8
  111. package/dist/types/wallet/serviceWorker/wallet.d.ts +67 -21
  112. package/dist/types/wallet/serviceWorker/worker.d.ts +16 -4
  113. package/dist/types/wallet/unroll.d.ts +1 -1
  114. package/dist/types/wallet/wallet.d.ts +5 -1
  115. package/package.json +39 -15
  116. package/dist/cjs/wallet/serviceWorker/db/vtxo/idb.js +0 -185
  117. package/dist/esm/wallet/serviceWorker/db/vtxo/idb.js +0 -181
  118. package/dist/types/wallet/serviceWorker/db/vtxo/idb.d.ts +0 -20
  119. package/dist/types/wallet/serviceWorker/db/vtxo/index.d.ts +0 -14
  120. /package/dist/cjs/{wallet/serviceWorker/db/vtxo → storage}/index.js +0 -0
  121. /package/dist/esm/{wallet/serviceWorker/db/vtxo → storage}/index.js +0 -0
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContractRepositoryImpl = void 0;
4
+ class ContractRepositoryImpl {
5
+ constructor(storage) {
6
+ this.cache = new Map();
7
+ this.storage = storage;
8
+ }
9
+ async getContractData(contractId, key) {
10
+ const storageKey = `contract:${contractId}:${key}`;
11
+ const cached = this.cache.get(storageKey);
12
+ if (cached !== undefined)
13
+ return cached;
14
+ const stored = await this.storage.getItem(storageKey);
15
+ if (!stored)
16
+ return null;
17
+ try {
18
+ const data = JSON.parse(stored);
19
+ this.cache.set(storageKey, data);
20
+ return data;
21
+ }
22
+ catch (error) {
23
+ console.error(`Failed to parse contract data for ${contractId}:${key}:`, error);
24
+ return null;
25
+ }
26
+ }
27
+ async setContractData(contractId, key, data) {
28
+ const storageKey = `contract:${contractId}:${key}`;
29
+ try {
30
+ // First persist to storage, only update cache if successful
31
+ await this.storage.setItem(storageKey, JSON.stringify(data));
32
+ this.cache.set(storageKey, data);
33
+ }
34
+ catch (error) {
35
+ // Storage operation failed, cache remains unchanged
36
+ console.error(`Failed to persist contract data for ${contractId}:${key}:`, error);
37
+ throw error; // Rethrow to notify caller of failure
38
+ }
39
+ }
40
+ async deleteContractData(contractId, key) {
41
+ const storageKey = `contract:${contractId}:${key}`;
42
+ try {
43
+ // First remove from persistent storage, only delete from cache if successful
44
+ await this.storage.removeItem(storageKey);
45
+ this.cache.delete(storageKey);
46
+ }
47
+ catch (error) {
48
+ // Storage operation failed, cache remains unchanged
49
+ console.error(`Failed to remove contract data for ${contractId}:${key}:`, error);
50
+ throw error; // Rethrow to notify caller of failure
51
+ }
52
+ }
53
+ async getContractCollection(contractType) {
54
+ const storageKey = `collection:${contractType}`;
55
+ const cached = this.cache.get(storageKey);
56
+ if (cached !== undefined)
57
+ return cached;
58
+ const stored = await this.storage.getItem(storageKey);
59
+ if (!stored) {
60
+ this.cache.set(storageKey, []);
61
+ return [];
62
+ }
63
+ try {
64
+ const collection = JSON.parse(stored);
65
+ this.cache.set(storageKey, collection);
66
+ return collection;
67
+ }
68
+ catch (error) {
69
+ console.error(`Failed to parse contract collection ${contractType}:`, error);
70
+ this.cache.set(storageKey, []);
71
+ return [];
72
+ }
73
+ }
74
+ async saveToContractCollection(contractType, item, idField) {
75
+ const collection = await this.getContractCollection(contractType);
76
+ // Validate that the item has the required id field
77
+ const itemId = item[idField];
78
+ if (itemId === undefined || itemId === null) {
79
+ throw new Error(`Item is missing required field '${String(idField)}'`);
80
+ }
81
+ // Find existing item index without mutating the original collection
82
+ const existingIndex = collection.findIndex((i) => i[idField] === itemId);
83
+ // Build new collection without mutating the cached one
84
+ let newCollection;
85
+ if (existingIndex !== -1) {
86
+ // Replace existing item
87
+ newCollection = [
88
+ ...collection.slice(0, existingIndex),
89
+ item,
90
+ ...collection.slice(existingIndex + 1),
91
+ ];
92
+ }
93
+ else {
94
+ // Add new item
95
+ newCollection = [...collection, item];
96
+ }
97
+ const storageKey = `collection:${contractType}`;
98
+ try {
99
+ // First persist to storage, only update cache if successful
100
+ await this.storage.setItem(storageKey, JSON.stringify(newCollection));
101
+ this.cache.set(storageKey, newCollection);
102
+ }
103
+ catch (error) {
104
+ // Storage operation failed, cache remains unchanged
105
+ console.error(`Failed to persist contract collection ${contractType}:`, error);
106
+ throw error; // Rethrow to notify caller of failure
107
+ }
108
+ }
109
+ async removeFromContractCollection(contractType, id, idField) {
110
+ // Validate input parameters
111
+ if (id === undefined || id === null) {
112
+ throw new Error(`Invalid id provided for removal: ${String(id)}`);
113
+ }
114
+ const collection = await this.getContractCollection(contractType);
115
+ // Build new collection without the specified item
116
+ const filtered = collection.filter((item) => item[idField] !== id);
117
+ const storageKey = `collection:${contractType}`;
118
+ try {
119
+ // First persist to storage, only update cache if successful
120
+ await this.storage.setItem(storageKey, JSON.stringify(filtered));
121
+ this.cache.set(storageKey, filtered);
122
+ }
123
+ catch (error) {
124
+ // Storage operation failed, cache remains unchanged
125
+ console.error(`Failed to persist contract collection removal for ${contractType}:`, error);
126
+ throw error; // Rethrow to notify caller of failure
127
+ }
128
+ }
129
+ }
130
+ exports.ContractRepositoryImpl = ContractRepositoryImpl;
@@ -0,0 +1,18 @@
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
+ __exportStar(require("./walletRepository"), exports);
18
+ __exportStar(require("./contractRepository"), exports);
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WalletRepositoryImpl = void 0;
4
+ class WalletRepositoryImpl {
5
+ constructor(storage) {
6
+ this.storage = storage;
7
+ this.cache = {
8
+ vtxos: new Map(),
9
+ transactions: new Map(),
10
+ walletState: null,
11
+ initialized: new Set(),
12
+ };
13
+ }
14
+ async getVtxos(address) {
15
+ const cacheKey = `vtxos:${address}`;
16
+ if (this.cache.vtxos.has(address)) {
17
+ return this.cache.vtxos.get(address);
18
+ }
19
+ const stored = await this.storage.getItem(cacheKey);
20
+ if (!stored) {
21
+ this.cache.vtxos.set(address, []);
22
+ return [];
23
+ }
24
+ try {
25
+ const vtxos = JSON.parse(stored);
26
+ this.cache.vtxos.set(address, vtxos);
27
+ return vtxos.slice();
28
+ }
29
+ catch (error) {
30
+ console.error(`Failed to parse VTXOs for address ${address}:`, error);
31
+ this.cache.vtxos.set(address, []);
32
+ return [];
33
+ }
34
+ }
35
+ async saveVtxo(address, vtxo) {
36
+ const vtxos = await this.getVtxos(address);
37
+ const existing = vtxos.findIndex((v) => v.txid === vtxo.txid && v.vout === vtxo.vout);
38
+ if (existing !== -1) {
39
+ vtxos[existing] = vtxo;
40
+ }
41
+ else {
42
+ vtxos.push(vtxo);
43
+ }
44
+ this.cache.vtxos.set(address, vtxos);
45
+ await this.storage.setItem(`vtxos:${address}`, JSON.stringify(vtxos));
46
+ }
47
+ async saveVtxos(address, vtxos) {
48
+ const storedVtxos = await this.getVtxos(address);
49
+ for (const vtxo of vtxos) {
50
+ const existing = storedVtxos.findIndex((v) => v.txid === vtxo.txid && v.vout === vtxo.vout);
51
+ if (existing !== -1) {
52
+ storedVtxos[existing] = vtxo;
53
+ }
54
+ else {
55
+ storedVtxos.push(vtxo);
56
+ }
57
+ }
58
+ this.cache.vtxos.set(address, storedVtxos);
59
+ await this.storage.setItem(`vtxos:${address}`, JSON.stringify(storedVtxos));
60
+ }
61
+ async removeVtxo(address, vtxoId) {
62
+ const vtxos = await this.getVtxos(address);
63
+ const [txid, vout] = vtxoId.split(":");
64
+ const filtered = vtxos.filter((v) => !(v.txid === txid && v.vout === parseInt(vout)));
65
+ this.cache.vtxos.set(address, filtered);
66
+ await this.storage.setItem(`vtxos:${address}`, JSON.stringify(filtered));
67
+ }
68
+ async clearVtxos(address) {
69
+ this.cache.vtxos.set(address, []);
70
+ await this.storage.removeItem(`vtxos:${address}`);
71
+ }
72
+ async getTransactionHistory(address) {
73
+ const cacheKey = `tx:${address}`;
74
+ if (this.cache.transactions.has(address)) {
75
+ return this.cache.transactions.get(address);
76
+ }
77
+ const stored = await this.storage.getItem(cacheKey);
78
+ if (!stored) {
79
+ this.cache.transactions.set(address, []);
80
+ return [];
81
+ }
82
+ try {
83
+ const transactions = JSON.parse(stored);
84
+ this.cache.transactions.set(address, transactions);
85
+ return transactions.slice();
86
+ }
87
+ catch (error) {
88
+ console.error(`Failed to parse transactions for address ${address}:`, error);
89
+ this.cache.transactions.set(address, []);
90
+ return [];
91
+ }
92
+ }
93
+ async saveTransaction(address, tx) {
94
+ const transactions = await this.getTransactionHistory(address);
95
+ const existing = transactions.findIndex((t) => t.id === tx.id);
96
+ if (existing !== -1) {
97
+ transactions[existing] = tx;
98
+ }
99
+ else {
100
+ transactions.push(tx);
101
+ // Sort by timestamp descending
102
+ transactions.sort((a, b) => b.timestamp - a.timestamp);
103
+ }
104
+ this.cache.transactions.set(address, transactions);
105
+ await this.storage.setItem(`tx:${address}`, JSON.stringify(transactions));
106
+ }
107
+ async getWalletState() {
108
+ if (this.cache.walletState !== null ||
109
+ this.cache.initialized.has("walletState")) {
110
+ return this.cache.walletState;
111
+ }
112
+ const stored = await this.storage.getItem("wallet:state");
113
+ if (!stored) {
114
+ this.cache.walletState = null;
115
+ this.cache.initialized.add("walletState");
116
+ return null;
117
+ }
118
+ try {
119
+ const state = JSON.parse(stored);
120
+ this.cache.walletState = state;
121
+ this.cache.initialized.add("walletState");
122
+ return state;
123
+ }
124
+ catch (error) {
125
+ console.error("Failed to parse wallet state:", error);
126
+ this.cache.walletState = null;
127
+ this.cache.initialized.add("walletState");
128
+ return null;
129
+ }
130
+ }
131
+ async saveWalletState(state) {
132
+ this.cache.walletState = state;
133
+ await this.storage.setItem("wallet:state", JSON.stringify(state));
134
+ }
135
+ }
136
+ exports.WalletRepositoryImpl = WalletRepositoryImpl;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ArkAddress = void 0;
4
4
  const base_1 = require("@scure/base");
5
- const btc_signer_1 = require("@scure/btc-signer");
5
+ const script_js_1 = require("@scure/btc-signer/script.js");
6
6
  /**
7
7
  * ArkAddress allows to create and decode bech32m encoded ark address.
8
8
  * An ark address is composed of:
@@ -66,11 +66,11 @@ class ArkAddress {
66
66
  }
67
67
  // pkScript is the script that should be used to send non-dust funds to the address
68
68
  get pkScript() {
69
- return btc_signer_1.Script.encode(["OP_1", this.vtxoTaprootKey]);
69
+ return script_js_1.Script.encode(["OP_1", this.vtxoTaprootKey]);
70
70
  }
71
71
  // subdustPkScript is the script that should be used to send sub-dust funds to the address
72
72
  get subdustPkScript() {
73
- return btc_signer_1.Script.encode(["RETURN", this.vtxoTaprootKey]);
73
+ return script_js_1.Script.encode(["RETURN", this.vtxoTaprootKey]);
74
74
  }
75
75
  }
76
76
  exports.ArkAddress = ArkAddress;
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VtxoScript = void 0;
4
4
  exports.scriptFromTapLeafScript = scriptFromTapLeafScript;
5
- const payment_1 = require("@scure/btc-signer/payment");
6
- const utils_1 = require("@scure/btc-signer/utils");
5
+ const payment_js_1 = require("@scure/btc-signer/payment.js");
6
+ const utils_js_1 = require("@scure/btc-signer/utils.js");
7
7
  const address_1 = require("./address");
8
- const btc_signer_1 = require("@scure/btc-signer");
8
+ const script_js_1 = require("@scure/btc-signer/script.js");
9
9
  const base_1 = require("@scure/base");
10
10
  const tapscript_1 = require("./tapscript");
11
11
  function scriptFromTapLeafScript(leaf) {
@@ -26,8 +26,8 @@ class VtxoScript {
26
26
  }
27
27
  constructor(scripts) {
28
28
  this.scripts = scripts;
29
- const tapTree = (0, payment_1.taprootListToTree)(scripts.map((script) => ({ script, leafVersion: payment_1.TAP_LEAF_VERSION })));
30
- const payment = (0, payment_1.p2tr)(utils_1.TAPROOT_UNSPENDABLE_KEY, tapTree, undefined, true);
29
+ const tapTree = (0, payment_js_1.taprootListToTree)(scripts.map((script) => ({ script, leafVersion: payment_js_1.TAP_LEAF_VERSION })));
30
+ const payment = (0, payment_js_1.p2tr)(utils_js_1.TAPROOT_UNSPENDABLE_KEY, tapTree, undefined, true);
31
31
  if (!payment.tapLeafScript ||
32
32
  payment.tapLeafScript.length !== scripts.length) {
33
33
  throw new Error("invalid scripts");
@@ -43,10 +43,10 @@ class VtxoScript {
43
43
  return new address_1.ArkAddress(serverPubKey, this.tweakedPublicKey, prefix);
44
44
  }
45
45
  get pkScript() {
46
- return btc_signer_1.Script.encode(["OP_1", this.tweakedPublicKey]);
46
+ return script_js_1.Script.encode(["OP_1", this.tweakedPublicKey]);
47
47
  }
48
48
  onchainAddress(network) {
49
- return (0, payment_1.Address)(network).encode({
49
+ return (0, payment_js_1.Address)(network).encode({
50
50
  type: "tr",
51
51
  pubkey: this.tweakedPublicKey,
52
52
  });
@@ -36,10 +36,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.CLTVMultisigTapscript = exports.ConditionMultisigTapscript = exports.ConditionCSVMultisigTapscript = exports.CSVMultisigTapscript = exports.MultisigTapscript = exports.TapscriptType = void 0;
37
37
  exports.decodeTapscript = decodeTapscript;
38
38
  const bip68 = __importStar(require("bip68"));
39
- const script_1 = require("@scure/btc-signer/script");
40
- const payment_1 = require("@scure/btc-signer/payment");
39
+ const script_js_1 = require("@scure/btc-signer/script.js");
40
+ const payment_js_1 = require("@scure/btc-signer/payment.js");
41
41
  const base_1 = require("@scure/base");
42
- const MinimalScriptNum = (0, script_1.ScriptNum)(undefined, true);
42
+ const MinimalScriptNum = (0, script_js_1.ScriptNum)(undefined, true);
43
43
  var TapscriptType;
44
44
  (function (TapscriptType) {
45
45
  TapscriptType["Multisig"] = "multisig";
@@ -109,7 +109,7 @@ var MultisigTapscript;
109
109
  return {
110
110
  type: TapscriptType.Multisig,
111
111
  params,
112
- script: (0, payment_1.p2tr_ms)(params.pubkeys.length, params.pubkeys).script,
112
+ script: (0, payment_js_1.p2tr_ms)(params.pubkeys.length, params.pubkeys).script,
113
113
  };
114
114
  }
115
115
  const asm = [];
@@ -126,7 +126,7 @@ var MultisigTapscript;
126
126
  return {
127
127
  type: TapscriptType.Multisig,
128
128
  params,
129
- script: script_1.Script.encode(asm),
129
+ script: script_js_1.Script.encode(asm),
130
130
  };
131
131
  }
132
132
  MultisigTapscript.encode = encode;
@@ -151,7 +151,7 @@ var MultisigTapscript;
151
151
  MultisigTapscript.decode = decode;
152
152
  // <pubkey> CHECKSIG <pubkey> CHECKSIGADD <len_keys> NUMEQUAL
153
153
  function decodeChecksigAdd(script) {
154
- const asm = script_1.Script.decode(script);
154
+ const asm = script_js_1.Script.decode(script);
155
155
  const pubkeys = [];
156
156
  let foundNumEqual = false;
157
157
  // Parse through ASM operations
@@ -201,7 +201,7 @@ var MultisigTapscript;
201
201
  }
202
202
  // <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
203
203
  function decodeChecksig(script) {
204
- const asm = script_1.Script.decode(script);
204
+ const asm = script_js_1.Script.decode(script);
205
205
  const pubkeys = [];
206
206
  // Parse through ASM operations
207
207
  for (let i = 0; i < asm.length; i++) {
@@ -278,7 +278,7 @@ var CSVMultisigTapscript;
278
278
  ];
279
279
  const multisigScript = MultisigTapscript.encode(params);
280
280
  const script = new Uint8Array([
281
- ...script_1.Script.encode(asm),
281
+ ...script_js_1.Script.encode(asm),
282
282
  ...multisigScript.script,
283
283
  ]);
284
284
  return {
@@ -292,7 +292,7 @@ var CSVMultisigTapscript;
292
292
  if (script.length === 0) {
293
293
  throw new Error("Failed to decode: script is empty");
294
294
  }
295
- const asm = script_1.Script.decode(script);
295
+ const asm = script_js_1.Script.decode(script);
296
296
  if (asm.length < 3) {
297
297
  throw new Error(`Invalid script: too short (expected at least 3)`);
298
298
  }
@@ -303,7 +303,7 @@ var CSVMultisigTapscript;
303
303
  if (asm[1] !== "CHECKSEQUENCEVERIFY" || asm[2] !== "DROP") {
304
304
  throw new Error("Invalid script: expected CHECKSEQUENCEVERIFY DROP");
305
305
  }
306
- const multisigScript = new Uint8Array(script_1.Script.encode(asm.slice(3)));
306
+ const multisigScript = new Uint8Array(script_js_1.Script.encode(asm.slice(3)));
307
307
  let multisig;
308
308
  try {
309
309
  multisig = MultisigTapscript.decode(multisigScript);
@@ -355,7 +355,7 @@ var ConditionCSVMultisigTapscript;
355
355
  function encode(params) {
356
356
  const script = new Uint8Array([
357
357
  ...params.conditionScript,
358
- ...script_1.Script.encode(["VERIFY"]),
358
+ ...script_js_1.Script.encode(["VERIFY"]),
359
359
  ...CSVMultisigTapscript.encode(params).script,
360
360
  ]);
361
361
  return {
@@ -369,7 +369,7 @@ var ConditionCSVMultisigTapscript;
369
369
  if (script.length === 0) {
370
370
  throw new Error("Failed to decode: script is empty");
371
371
  }
372
- const asm = script_1.Script.decode(script);
372
+ const asm = script_js_1.Script.decode(script);
373
373
  if (asm.length < 1) {
374
374
  throw new Error(`Invalid script: too short (expected at least 1)`);
375
375
  }
@@ -382,8 +382,8 @@ var ConditionCSVMultisigTapscript;
382
382
  if (verifyIndex === -1) {
383
383
  throw new Error("Invalid script: missing VERIFY operation");
384
384
  }
385
- const conditionScript = new Uint8Array(script_1.Script.encode(asm.slice(0, verifyIndex)));
386
- const csvMultisigScript = new Uint8Array(script_1.Script.encode(asm.slice(verifyIndex + 1)));
385
+ const conditionScript = new Uint8Array(script_js_1.Script.encode(asm.slice(0, verifyIndex)));
386
+ const csvMultisigScript = new Uint8Array(script_js_1.Script.encode(asm.slice(verifyIndex + 1)));
387
387
  let csvMultisig;
388
388
  try {
389
389
  csvMultisig = CSVMultisigTapscript.decode(csvMultisigScript);
@@ -430,7 +430,7 @@ var ConditionMultisigTapscript;
430
430
  function encode(params) {
431
431
  const script = new Uint8Array([
432
432
  ...params.conditionScript,
433
- ...script_1.Script.encode(["VERIFY"]),
433
+ ...script_js_1.Script.encode(["VERIFY"]),
434
434
  ...MultisigTapscript.encode(params).script,
435
435
  ]);
436
436
  return {
@@ -444,7 +444,7 @@ var ConditionMultisigTapscript;
444
444
  if (script.length === 0) {
445
445
  throw new Error("Failed to decode: script is empty");
446
446
  }
447
- const asm = script_1.Script.decode(script);
447
+ const asm = script_js_1.Script.decode(script);
448
448
  if (asm.length < 1) {
449
449
  throw new Error(`Invalid script: too short (expected at least 1)`);
450
450
  }
@@ -457,8 +457,8 @@ var ConditionMultisigTapscript;
457
457
  if (verifyIndex === -1) {
458
458
  throw new Error("Invalid script: missing VERIFY operation");
459
459
  }
460
- const conditionScript = new Uint8Array(script_1.Script.encode(asm.slice(0, verifyIndex)));
461
- const multisigScript = new Uint8Array(script_1.Script.encode(asm.slice(verifyIndex + 1)));
460
+ const conditionScript = new Uint8Array(script_js_1.Script.encode(asm.slice(0, verifyIndex)));
461
+ const multisigScript = new Uint8Array(script_js_1.Script.encode(asm.slice(verifyIndex + 1)));
462
462
  let multisig;
463
463
  try {
464
464
  multisig = MultisigTapscript.decode(multisigScript);
@@ -509,7 +509,7 @@ var CLTVMultisigTapscript;
509
509
  "CHECKLOCKTIMEVERIFY",
510
510
  "DROP",
511
511
  ];
512
- const timelockedScript = script_1.Script.encode(asm);
512
+ const timelockedScript = script_js_1.Script.encode(asm);
513
513
  const script = new Uint8Array([
514
514
  ...timelockedScript,
515
515
  ...MultisigTapscript.encode(params).script,
@@ -525,7 +525,7 @@ var CLTVMultisigTapscript;
525
525
  if (script.length === 0) {
526
526
  throw new Error("Failed to decode: script is empty");
527
527
  }
528
- const asm = script_1.Script.decode(script);
528
+ const asm = script_js_1.Script.decode(script);
529
529
  if (asm.length < 3) {
530
530
  throw new Error(`Invalid script: too short (expected at least 3)`);
531
531
  }
@@ -536,7 +536,7 @@ var CLTVMultisigTapscript;
536
536
  if (asm[1] !== "CHECKLOCKTIMEVERIFY" || asm[2] !== "DROP") {
537
537
  throw new Error("Invalid script: expected CHECKLOCKTIMEVERIFY DROP");
538
538
  }
539
- const multisigScript = new Uint8Array(script_1.Script.encode(asm.slice(3)));
539
+ const multisigScript = new Uint8Array(script_js_1.Script.encode(asm.slice(3)));
540
540
  let multisig;
541
541
  try {
542
542
  multisig = MultisigTapscript.decode(multisigScript);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VHTLC = void 0;
4
- const btc_signer_1 = require("@scure/btc-signer");
4
+ const script_js_1 = require("@scure/btc-signer/script.js");
5
5
  const tapscript_1 = require("./tapscript");
6
6
  const base_1 = require("@scure/base");
7
7
  const base_2 = require("./base");
@@ -158,5 +158,5 @@ var VHTLC;
158
158
  }
159
159
  })(VHTLC || (exports.VHTLC = VHTLC = {}));
160
160
  function preimageConditionScript(preimageHash) {
161
- return btc_signer_1.Script.encode(["HASH160", preimageHash, "EQUAL"]);
161
+ return script_js_1.Script.encode(["HASH160", preimageHash, "EQUAL"]);
162
162
  }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncStorageAdapter = void 0;
4
+ // Note: This requires @react-native-async-storage/async-storage to be installed
5
+ class AsyncStorageAdapter {
6
+ constructor() {
7
+ try {
8
+ // Dynamic import to avoid errors in non-React Native environments
9
+ this.AsyncStorage =
10
+ require("@react-native-async-storage/async-storage").default;
11
+ }
12
+ catch (error) {
13
+ throw new Error("AsyncStorage is not available. Make sure @react-native-async-storage/async-storage is installed in React Native environment.");
14
+ }
15
+ }
16
+ async getItem(key) {
17
+ return await this.AsyncStorage.getItem(key);
18
+ }
19
+ async setItem(key, value) {
20
+ try {
21
+ await this.AsyncStorage.setItem(key, value);
22
+ }
23
+ catch (error) {
24
+ console.error(`Failed to set item for key ${key}:`, error);
25
+ throw error;
26
+ }
27
+ }
28
+ async removeItem(key) {
29
+ try {
30
+ await this.AsyncStorage.removeItem(key);
31
+ }
32
+ catch (error) {
33
+ console.error(`Failed to remove item for key ${key}:`, error);
34
+ throw error;
35
+ }
36
+ }
37
+ async clear() {
38
+ try {
39
+ await this.AsyncStorage.clear();
40
+ }
41
+ catch (error) {
42
+ console.error("Failed to clear AsyncStorage:", error);
43
+ throw error;
44
+ }
45
+ }
46
+ }
47
+ exports.AsyncStorageAdapter = AsyncStorageAdapter;