@arkade-os/sdk 0.3.13 → 0.4.0-next.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.
- package/README.md +586 -54
- package/dist/cjs/asset/assetGroup.js +141 -0
- package/dist/cjs/asset/assetId.js +88 -0
- package/dist/cjs/asset/assetInput.js +204 -0
- package/dist/cjs/asset/assetOutput.js +159 -0
- package/dist/cjs/asset/assetRef.js +82 -0
- package/dist/cjs/asset/index.js +24 -0
- package/dist/cjs/asset/metadata.js +172 -0
- package/dist/cjs/asset/packet.js +164 -0
- package/dist/cjs/asset/types.js +25 -0
- package/dist/cjs/asset/utils.js +105 -0
- package/dist/cjs/bip322/index.js +270 -0
- package/dist/cjs/contracts/arkcontract.js +148 -0
- package/dist/cjs/contracts/contractManager.js +436 -0
- package/dist/cjs/contracts/contractWatcher.js +567 -0
- package/dist/cjs/contracts/handlers/default.js +85 -0
- package/dist/cjs/contracts/handlers/delegate.js +89 -0
- package/dist/cjs/contracts/handlers/helpers.js +105 -0
- package/dist/cjs/contracts/handlers/index.js +19 -0
- package/dist/cjs/contracts/handlers/registry.js +89 -0
- package/dist/cjs/contracts/handlers/vhtlc.js +193 -0
- package/dist/cjs/contracts/index.js +41 -0
- package/dist/cjs/contracts/types.js +2 -0
- package/dist/cjs/forfeit.js +12 -8
- package/dist/cjs/identity/index.js +1 -0
- package/dist/cjs/identity/seedIdentity.js +255 -0
- package/dist/cjs/index.js +72 -14
- package/dist/cjs/intent/index.js +47 -11
- package/dist/cjs/providers/ark.js +7 -0
- package/dist/cjs/providers/delegator.js +66 -0
- package/dist/cjs/providers/expoIndexer.js +5 -0
- package/dist/cjs/providers/indexer.js +68 -1
- package/dist/cjs/providers/utils.js +1 -0
- package/dist/cjs/repositories/contractRepository.js +0 -103
- package/dist/cjs/repositories/inMemory/contractRepository.js +55 -0
- package/dist/cjs/repositories/inMemory/walletRepository.js +80 -0
- package/dist/cjs/repositories/index.js +16 -0
- package/dist/cjs/repositories/indexedDB/contractRepository.js +187 -0
- package/dist/cjs/repositories/indexedDB/db.js +19 -0
- package/dist/cjs/repositories/indexedDB/manager.js +97 -0
- package/dist/cjs/repositories/indexedDB/schema.js +159 -0
- package/dist/cjs/repositories/indexedDB/walletRepository.js +338 -0
- package/dist/cjs/repositories/indexedDB/websqlAdapter.js +144 -0
- package/dist/cjs/repositories/migrations/contractRepositoryImpl.js +127 -0
- package/dist/cjs/repositories/migrations/fromStorageAdapter.js +66 -0
- package/dist/cjs/repositories/migrations/walletRepositoryImpl.js +180 -0
- package/dist/cjs/repositories/realm/contractRepository.js +120 -0
- package/dist/cjs/repositories/realm/index.js +9 -0
- package/dist/cjs/repositories/realm/schemas.js +108 -0
- package/dist/cjs/repositories/realm/types.js +7 -0
- package/dist/cjs/repositories/realm/walletRepository.js +273 -0
- package/dist/cjs/repositories/serialization.js +49 -0
- package/dist/cjs/repositories/sqlite/contractRepository.js +139 -0
- package/dist/cjs/repositories/sqlite/index.js +7 -0
- package/dist/cjs/repositories/sqlite/types.js +2 -0
- package/dist/cjs/repositories/sqlite/walletRepository.js +328 -0
- package/dist/cjs/repositories/walletRepository.js +0 -169
- package/dist/cjs/script/base.js +54 -0
- package/dist/cjs/script/delegate.js +49 -0
- package/dist/cjs/storage/asyncStorage.js +4 -1
- package/dist/cjs/storage/fileSystem.js +3 -0
- package/dist/cjs/storage/inMemory.js +3 -0
- package/dist/cjs/storage/indexedDB.js +5 -1
- package/dist/cjs/storage/localStorage.js +3 -0
- package/dist/cjs/utils/arkTransaction.js +16 -0
- package/dist/cjs/utils/transactionHistory.js +50 -0
- package/dist/cjs/wallet/asset-manager.js +338 -0
- package/dist/cjs/wallet/asset.js +117 -0
- package/dist/cjs/wallet/batch.js +1 -1
- package/dist/cjs/wallet/delegator.js +235 -0
- package/dist/cjs/wallet/expo/background.js +133 -0
- package/dist/cjs/wallet/expo/index.js +9 -0
- package/dist/cjs/wallet/expo/wallet.js +231 -0
- package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +568 -0
- package/dist/cjs/wallet/serviceWorker/wallet.js +383 -102
- package/dist/cjs/wallet/utils.js +58 -0
- package/dist/cjs/wallet/validation.js +151 -0
- package/dist/cjs/wallet/vtxo-manager.js +8 -1
- package/dist/cjs/wallet/wallet.js +702 -260
- package/dist/cjs/worker/browser/service-worker-manager.js +82 -0
- package/dist/cjs/{wallet/serviceWorker → worker/browser}/utils.js +2 -1
- package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +78 -0
- package/dist/cjs/worker/expo/index.js +12 -0
- package/dist/cjs/worker/expo/processors/contractPollProcessor.js +61 -0
- package/dist/cjs/worker/expo/processors/index.js +6 -0
- package/dist/cjs/worker/expo/taskQueue.js +41 -0
- package/dist/cjs/worker/expo/taskRunner.js +57 -0
- package/dist/cjs/worker/messageBus.js +252 -0
- package/dist/esm/asset/assetGroup.js +137 -0
- package/dist/esm/asset/assetId.js +84 -0
- package/dist/esm/asset/assetInput.js +199 -0
- package/dist/esm/asset/assetOutput.js +154 -0
- package/dist/esm/asset/assetRef.js +78 -0
- package/dist/esm/asset/index.js +8 -0
- package/dist/esm/asset/metadata.js +167 -0
- package/dist/esm/asset/packet.js +159 -0
- package/dist/esm/asset/types.js +22 -0
- package/dist/esm/asset/utils.js +99 -0
- package/dist/esm/bip322/index.js +267 -0
- package/dist/esm/contracts/arkcontract.js +141 -0
- package/dist/esm/contracts/contractManager.js +432 -0
- package/dist/esm/contracts/contractWatcher.js +563 -0
- package/dist/esm/contracts/handlers/default.js +82 -0
- package/dist/esm/contracts/handlers/delegate.js +86 -0
- package/dist/esm/contracts/handlers/helpers.js +66 -0
- package/dist/esm/contracts/handlers/index.js +12 -0
- package/dist/esm/contracts/handlers/registry.js +86 -0
- package/dist/esm/contracts/handlers/vhtlc.js +190 -0
- package/dist/esm/contracts/index.js +13 -0
- package/dist/esm/contracts/types.js +1 -0
- package/dist/esm/forfeit.js +11 -8
- package/dist/esm/identity/index.js +1 -0
- package/dist/esm/identity/seedIdentity.js +249 -0
- package/dist/esm/index.js +28 -15
- package/dist/esm/intent/index.js +44 -9
- package/dist/esm/providers/ark.js +7 -0
- package/dist/esm/providers/delegator.js +62 -0
- package/dist/esm/providers/expoIndexer.js +5 -0
- package/dist/esm/providers/indexer.js +68 -1
- package/dist/esm/providers/utils.js +1 -0
- package/dist/esm/repositories/contractRepository.js +1 -101
- package/dist/esm/repositories/inMemory/contractRepository.js +51 -0
- package/dist/esm/repositories/inMemory/walletRepository.js +76 -0
- package/dist/esm/repositories/index.js +8 -0
- package/dist/esm/repositories/indexedDB/contractRepository.js +183 -0
- package/dist/esm/repositories/indexedDB/db.js +4 -0
- package/dist/esm/repositories/indexedDB/manager.js +92 -0
- package/dist/esm/repositories/indexedDB/schema.js +155 -0
- package/dist/esm/repositories/indexedDB/walletRepository.js +334 -0
- package/dist/esm/repositories/indexedDB/websqlAdapter.js +138 -0
- package/dist/esm/repositories/migrations/contractRepositoryImpl.js +121 -0
- package/dist/esm/repositories/migrations/fromStorageAdapter.js +58 -0
- package/dist/esm/repositories/migrations/walletRepositoryImpl.js +176 -0
- package/dist/esm/repositories/realm/contractRepository.js +116 -0
- package/dist/esm/repositories/realm/index.js +3 -0
- package/dist/esm/repositories/realm/schemas.js +105 -0
- package/dist/esm/repositories/realm/types.js +6 -0
- package/dist/esm/repositories/realm/walletRepository.js +269 -0
- package/dist/esm/repositories/serialization.js +40 -0
- package/dist/esm/repositories/sqlite/contractRepository.js +135 -0
- package/dist/esm/repositories/sqlite/index.js +2 -0
- package/dist/esm/repositories/sqlite/types.js +1 -0
- package/dist/esm/repositories/sqlite/walletRepository.js +324 -0
- package/dist/esm/repositories/walletRepository.js +1 -167
- package/dist/esm/script/base.js +21 -1
- package/dist/esm/script/delegate.js +46 -0
- package/dist/esm/storage/asyncStorage.js +4 -1
- package/dist/esm/storage/fileSystem.js +3 -0
- package/dist/esm/storage/inMemory.js +3 -0
- package/dist/esm/storage/indexedDB.js +5 -1
- package/dist/esm/storage/localStorage.js +3 -0
- package/dist/esm/utils/arkTransaction.js +15 -0
- package/dist/esm/utils/transactionHistory.js +50 -0
- package/dist/esm/wallet/asset-manager.js +333 -0
- package/dist/esm/wallet/asset.js +111 -0
- package/dist/esm/wallet/batch.js +1 -1
- package/dist/esm/wallet/delegator.js +231 -0
- package/dist/esm/wallet/expo/background.js +128 -0
- package/dist/esm/wallet/expo/index.js +2 -0
- package/dist/esm/wallet/expo/wallet.js +194 -0
- package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +564 -0
- package/dist/esm/wallet/serviceWorker/wallet.js +382 -101
- package/dist/esm/wallet/utils.js +54 -0
- package/dist/esm/wallet/validation.js +139 -0
- package/dist/esm/wallet/vtxo-manager.js +8 -1
- package/dist/esm/wallet/wallet.js +704 -229
- package/dist/esm/worker/browser/service-worker-manager.js +76 -0
- package/dist/esm/{wallet/serviceWorker → worker/browser}/utils.js +2 -1
- package/dist/esm/worker/expo/asyncStorageTaskQueue.js +74 -0
- package/dist/esm/worker/expo/index.js +4 -0
- package/dist/esm/worker/expo/processors/contractPollProcessor.js +58 -0
- package/dist/esm/worker/expo/processors/index.js +1 -0
- package/dist/esm/worker/expo/taskQueue.js +37 -0
- package/dist/esm/worker/expo/taskRunner.js +54 -0
- package/dist/esm/worker/messageBus.js +248 -0
- package/dist/types/asset/assetGroup.d.ts +28 -0
- package/dist/types/asset/assetId.d.ts +19 -0
- package/dist/types/asset/assetInput.d.ts +46 -0
- package/dist/types/asset/assetOutput.d.ts +39 -0
- package/dist/types/asset/assetRef.d.ts +25 -0
- package/dist/types/asset/index.d.ts +8 -0
- package/dist/types/asset/metadata.d.ts +37 -0
- package/dist/types/asset/packet.d.ts +27 -0
- package/dist/types/asset/types.d.ts +18 -0
- package/dist/types/asset/utils.d.ts +21 -0
- package/dist/types/bip322/index.d.ts +55 -0
- package/dist/types/contracts/arkcontract.d.ts +101 -0
- package/dist/types/contracts/contractManager.d.ts +331 -0
- package/dist/types/contracts/contractWatcher.d.ts +192 -0
- package/dist/types/contracts/handlers/default.d.ts +19 -0
- package/dist/types/contracts/handlers/delegate.d.ts +21 -0
- package/dist/types/contracts/handlers/helpers.d.ts +18 -0
- package/dist/types/contracts/handlers/index.d.ts +7 -0
- package/dist/types/contracts/handlers/registry.d.ts +65 -0
- package/dist/types/contracts/handlers/vhtlc.d.ts +32 -0
- package/dist/types/contracts/index.d.ts +14 -0
- package/dist/types/contracts/types.d.ts +222 -0
- package/dist/types/forfeit.d.ts +2 -1
- package/dist/types/identity/index.d.ts +1 -0
- package/dist/types/identity/seedIdentity.d.ts +128 -0
- package/dist/types/index.d.ts +22 -12
- package/dist/types/intent/index.d.ts +15 -1
- package/dist/types/providers/ark.d.ts +11 -2
- package/dist/types/providers/delegator.d.ts +29 -0
- package/dist/types/providers/indexer.d.ts +11 -1
- package/dist/types/repositories/contractRepository.d.ts +30 -19
- package/dist/types/repositories/inMemory/contractRepository.d.ts +17 -0
- package/dist/types/repositories/inMemory/walletRepository.d.ts +26 -0
- package/dist/types/repositories/index.d.ts +7 -0
- package/dist/types/repositories/indexedDB/contractRepository.d.ts +21 -0
- package/dist/types/repositories/indexedDB/db.d.ts +4 -0
- package/dist/types/repositories/indexedDB/manager.d.ts +22 -0
- package/dist/types/repositories/indexedDB/schema.d.ts +8 -0
- package/dist/types/repositories/indexedDB/walletRepository.d.ts +25 -0
- package/dist/types/repositories/indexedDB/websqlAdapter.d.ts +49 -0
- package/dist/types/repositories/migrations/contractRepositoryImpl.d.ts +24 -0
- package/dist/types/repositories/migrations/fromStorageAdapter.d.ts +19 -0
- package/dist/types/repositories/migrations/walletRepositoryImpl.d.ts +27 -0
- package/dist/types/repositories/realm/contractRepository.d.ts +24 -0
- package/dist/types/repositories/realm/index.d.ts +4 -0
- package/dist/types/repositories/realm/schemas.d.ts +208 -0
- package/dist/types/repositories/realm/types.d.ts +16 -0
- package/dist/types/repositories/realm/walletRepository.d.ts +31 -0
- package/dist/types/repositories/serialization.d.ts +40 -0
- package/dist/types/repositories/sqlite/contractRepository.d.ts +33 -0
- package/dist/types/repositories/sqlite/index.d.ts +3 -0
- package/dist/types/repositories/sqlite/types.d.ts +18 -0
- package/dist/types/repositories/sqlite/walletRepository.d.ts +40 -0
- package/dist/types/repositories/walletRepository.d.ts +13 -24
- package/dist/types/script/base.d.ts +1 -0
- package/dist/types/script/delegate.d.ts +36 -0
- package/dist/types/storage/asyncStorage.d.ts +4 -0
- package/dist/types/storage/fileSystem.d.ts +3 -0
- package/dist/types/storage/inMemory.d.ts +3 -0
- package/dist/types/storage/index.d.ts +3 -0
- package/dist/types/storage/indexedDB.d.ts +3 -0
- package/dist/types/storage/localStorage.d.ts +3 -0
- package/dist/types/utils/arkTransaction.d.ts +6 -0
- package/dist/types/wallet/asset-manager.d.ts +78 -0
- package/dist/types/wallet/asset.d.ts +21 -0
- package/dist/types/wallet/batch.d.ts +1 -1
- package/dist/types/wallet/delegator.d.ts +24 -0
- package/dist/types/wallet/expo/background.d.ts +66 -0
- package/dist/types/wallet/expo/index.d.ts +4 -0
- package/dist/types/wallet/expo/wallet.d.ts +97 -0
- package/dist/types/wallet/index.d.ts +75 -2
- package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +366 -0
- package/dist/types/wallet/serviceWorker/wallet.d.ts +20 -11
- package/dist/types/wallet/utils.d.ts +12 -1
- package/dist/types/wallet/validation.d.ts +24 -0
- package/dist/types/wallet/wallet.d.ts +111 -17
- package/dist/types/worker/browser/service-worker-manager.d.ts +21 -0
- package/dist/types/{wallet/serviceWorker → worker/browser}/utils.d.ts +2 -1
- package/dist/types/worker/expo/asyncStorageTaskQueue.d.ts +46 -0
- package/dist/types/worker/expo/index.d.ts +7 -0
- package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +14 -0
- package/dist/types/worker/expo/processors/index.d.ts +1 -0
- package/dist/types/worker/expo/taskQueue.d.ts +50 -0
- package/dist/types/worker/expo/taskRunner.d.ts +42 -0
- package/dist/types/worker/messageBus.d.ts +109 -0
- package/package.json +69 -11
- package/dist/cjs/wallet/serviceWorker/request.js +0 -78
- package/dist/cjs/wallet/serviceWorker/response.js +0 -222
- package/dist/cjs/wallet/serviceWorker/worker.js +0 -655
- package/dist/esm/wallet/serviceWorker/request.js +0 -75
- package/dist/esm/wallet/serviceWorker/response.js +0 -219
- package/dist/esm/wallet/serviceWorker/worker.js +0 -651
- package/dist/types/wallet/serviceWorker/request.d.ts +0 -74
- package/dist/types/wallet/serviceWorker/response.d.ts +0 -123
- package/dist/types/wallet/serviceWorker/worker.d.ts +0 -53
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Realm object schemas for the Ark wallet.
|
|
4
|
+
*
|
|
5
|
+
* All schema names are prefixed with "Ark" to avoid collisions with
|
|
6
|
+
* other Realm schemas in the consuming application.
|
|
7
|
+
*
|
|
8
|
+
* Since `realm` is a peer dependency (not installed in this package),
|
|
9
|
+
* schemas are defined as plain JS objects conforming to Realm's
|
|
10
|
+
* ObjectSchema shape.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.ArkRealmSchemas = exports.ArkContractSchema = exports.ArkWalletStateSchema = exports.ArkTransactionSchema = exports.ArkUtxoSchema = exports.ArkVtxoSchema = void 0;
|
|
14
|
+
exports.ArkVtxoSchema = {
|
|
15
|
+
name: "ArkVtxo",
|
|
16
|
+
primaryKey: "pk",
|
|
17
|
+
properties: {
|
|
18
|
+
pk: "string", // composite: `${txid}:${vout}`
|
|
19
|
+
address: { type: "string", indexed: true },
|
|
20
|
+
txid: "string",
|
|
21
|
+
vout: "int",
|
|
22
|
+
value: "int",
|
|
23
|
+
tapTree: "string", // hex-encoded
|
|
24
|
+
forfeitCb: "string",
|
|
25
|
+
forfeitS: "string",
|
|
26
|
+
intentCb: "string",
|
|
27
|
+
intentS: "string",
|
|
28
|
+
extraWitnessJson: "string?",
|
|
29
|
+
statusJson: "string",
|
|
30
|
+
virtualStatusJson: "string",
|
|
31
|
+
spentBy: "string?",
|
|
32
|
+
settledBy: "string?",
|
|
33
|
+
arkTxId: "string?",
|
|
34
|
+
createdAt: "string", // ISO 8601
|
|
35
|
+
isUnrolled: "bool",
|
|
36
|
+
isSpent: "bool?",
|
|
37
|
+
assetsJson: "string?",
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
exports.ArkUtxoSchema = {
|
|
41
|
+
name: "ArkUtxo",
|
|
42
|
+
primaryKey: "pk",
|
|
43
|
+
properties: {
|
|
44
|
+
pk: "string", // composite: `${txid}:${vout}`
|
|
45
|
+
address: { type: "string", indexed: true },
|
|
46
|
+
txid: "string",
|
|
47
|
+
vout: "int",
|
|
48
|
+
value: "int",
|
|
49
|
+
tapTree: "string", // hex-encoded
|
|
50
|
+
forfeitCb: "string",
|
|
51
|
+
forfeitS: "string",
|
|
52
|
+
intentCb: "string",
|
|
53
|
+
intentS: "string",
|
|
54
|
+
extraWitnessJson: "string?",
|
|
55
|
+
statusJson: "string",
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
exports.ArkTransactionSchema = {
|
|
59
|
+
name: "ArkTransaction",
|
|
60
|
+
primaryKey: "pk",
|
|
61
|
+
properties: {
|
|
62
|
+
pk: "string", // composite: `${address}:${boardingTxid}:${commitmentTxid}:${arkTxid}`
|
|
63
|
+
address: { type: "string", indexed: true },
|
|
64
|
+
boardingTxid: "string",
|
|
65
|
+
commitmentTxid: "string",
|
|
66
|
+
arkTxid: "string",
|
|
67
|
+
type: "string",
|
|
68
|
+
amount: "int",
|
|
69
|
+
settled: "bool",
|
|
70
|
+
createdAt: "int",
|
|
71
|
+
assetsJson: "string?",
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
exports.ArkWalletStateSchema = {
|
|
75
|
+
name: "ArkWalletState",
|
|
76
|
+
primaryKey: "key",
|
|
77
|
+
properties: {
|
|
78
|
+
key: "string",
|
|
79
|
+
lastSyncTime: "int?",
|
|
80
|
+
settingsJson: "string?",
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
exports.ArkContractSchema = {
|
|
84
|
+
name: "ArkContract",
|
|
85
|
+
primaryKey: "script",
|
|
86
|
+
properties: {
|
|
87
|
+
script: "string",
|
|
88
|
+
address: "string",
|
|
89
|
+
type: { type: "string", indexed: true },
|
|
90
|
+
state: { type: "string", indexed: true },
|
|
91
|
+
paramsJson: "string",
|
|
92
|
+
createdAt: "int",
|
|
93
|
+
expiresAt: "int?",
|
|
94
|
+
label: "string?",
|
|
95
|
+
metadataJson: "string?",
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* All Realm schemas needed by the Ark wallet repositories.
|
|
100
|
+
* Pass this array to your Realm configuration's `schema` property.
|
|
101
|
+
*/
|
|
102
|
+
exports.ArkRealmSchemas = [
|
|
103
|
+
exports.ArkVtxoSchema,
|
|
104
|
+
exports.ArkUtxoSchema,
|
|
105
|
+
exports.ArkTransactionSchema,
|
|
106
|
+
exports.ArkWalletStateSchema,
|
|
107
|
+
exports.ArkContractSchema,
|
|
108
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal interface for the subset of the Realm API used by the
|
|
4
|
+
* Ark repositories. Consumers pass their real Realm instance and
|
|
5
|
+
* the compiler validates it satisfies this shape.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RealmWalletRepository = void 0;
|
|
4
|
+
const serialization_1 = require("../serialization");
|
|
5
|
+
/**
|
|
6
|
+
* Realm-based implementation of WalletRepository.
|
|
7
|
+
*
|
|
8
|
+
* Consumers must open Realm with the schemas from `./schemas.ts` and pass
|
|
9
|
+
* the instance to the constructor.
|
|
10
|
+
*
|
|
11
|
+
* Realm handles schema creation on open, so `ensureInit()` is a no-op.
|
|
12
|
+
* The consumer owns the Realm lifecycle — `[Symbol.asyncDispose]` is a no-op.
|
|
13
|
+
*/
|
|
14
|
+
class RealmWalletRepository {
|
|
15
|
+
constructor(realm) {
|
|
16
|
+
this.realm = realm;
|
|
17
|
+
this.version = 1;
|
|
18
|
+
}
|
|
19
|
+
// ── Lifecycle ──────────────────────────────────────────────────────
|
|
20
|
+
async ensureInit() {
|
|
21
|
+
// Realm handles schema on open — nothing to initialise.
|
|
22
|
+
}
|
|
23
|
+
async [Symbol.asyncDispose]() {
|
|
24
|
+
// no-op — consumer owns the Realm lifecycle
|
|
25
|
+
}
|
|
26
|
+
// ── Clear ──────────────────────────────────────────────────────────
|
|
27
|
+
async clear() {
|
|
28
|
+
await this.ensureInit();
|
|
29
|
+
this.realm.write(() => {
|
|
30
|
+
this.realm.delete(this.realm.objects("ArkVtxo"));
|
|
31
|
+
this.realm.delete(this.realm.objects("ArkUtxo"));
|
|
32
|
+
this.realm.delete(this.realm.objects("ArkTransaction"));
|
|
33
|
+
this.realm.delete(this.realm.objects("ArkWalletState"));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// ── VTXO management ────────────────────────────────────────────────
|
|
37
|
+
async getVtxos(address) {
|
|
38
|
+
await this.ensureInit();
|
|
39
|
+
const results = this.realm
|
|
40
|
+
.objects("ArkVtxo")
|
|
41
|
+
.filtered("address == $0", address);
|
|
42
|
+
return [...results].map(vtxoObjectToDomain);
|
|
43
|
+
}
|
|
44
|
+
async saveVtxos(address, vtxos) {
|
|
45
|
+
await this.ensureInit();
|
|
46
|
+
this.realm.write(() => {
|
|
47
|
+
for (const vtxo of vtxos) {
|
|
48
|
+
const s = (0, serialization_1.serializeVtxo)(vtxo);
|
|
49
|
+
this.realm.create("ArkVtxo", {
|
|
50
|
+
pk: `${s.txid}:${s.vout}`,
|
|
51
|
+
address,
|
|
52
|
+
txid: s.txid,
|
|
53
|
+
vout: s.vout,
|
|
54
|
+
value: s.value,
|
|
55
|
+
tapTree: s.tapTree,
|
|
56
|
+
forfeitCb: s.forfeitTapLeafScript.cb,
|
|
57
|
+
forfeitS: s.forfeitTapLeafScript.s,
|
|
58
|
+
intentCb: s.intentTapLeafScript.cb,
|
|
59
|
+
intentS: s.intentTapLeafScript.s,
|
|
60
|
+
statusJson: JSON.stringify(s.status),
|
|
61
|
+
virtualStatusJson: JSON.stringify(s.virtualStatus),
|
|
62
|
+
createdAt: typeof s.createdAt === "string"
|
|
63
|
+
? s.createdAt
|
|
64
|
+
: s.createdAt instanceof Date
|
|
65
|
+
? s.createdAt.toISOString()
|
|
66
|
+
: new Date(s.createdAt).toISOString(),
|
|
67
|
+
isUnrolled: s.isUnrolled ?? false,
|
|
68
|
+
isSpent: s.isSpent === undefined ? null : s.isSpent,
|
|
69
|
+
spentBy: s.spentBy ?? null,
|
|
70
|
+
settledBy: s.settledBy ?? null,
|
|
71
|
+
arkTxId: s.arkTxId ?? null,
|
|
72
|
+
extraWitnessJson: s.extraWitness
|
|
73
|
+
? JSON.stringify(s.extraWitness)
|
|
74
|
+
: null,
|
|
75
|
+
assetsJson: s.assets ? JSON.stringify(s.assets) : null,
|
|
76
|
+
}, "modified");
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async deleteVtxos(address) {
|
|
81
|
+
await this.ensureInit();
|
|
82
|
+
this.realm.write(() => {
|
|
83
|
+
const toDelete = this.realm
|
|
84
|
+
.objects("ArkVtxo")
|
|
85
|
+
.filtered("address == $0", address);
|
|
86
|
+
this.realm.delete(toDelete);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
// ── UTXO management ────────────────────────────────────────────────
|
|
90
|
+
async getUtxos(address) {
|
|
91
|
+
await this.ensureInit();
|
|
92
|
+
const results = this.realm
|
|
93
|
+
.objects("ArkUtxo")
|
|
94
|
+
.filtered("address == $0", address);
|
|
95
|
+
return [...results].map(utxoObjectToDomain);
|
|
96
|
+
}
|
|
97
|
+
async saveUtxos(address, utxos) {
|
|
98
|
+
await this.ensureInit();
|
|
99
|
+
this.realm.write(() => {
|
|
100
|
+
for (const utxo of utxos) {
|
|
101
|
+
const s = (0, serialization_1.serializeUtxo)(utxo);
|
|
102
|
+
this.realm.create("ArkUtxo", {
|
|
103
|
+
pk: `${s.txid}:${s.vout}`,
|
|
104
|
+
address,
|
|
105
|
+
txid: s.txid,
|
|
106
|
+
vout: s.vout,
|
|
107
|
+
value: s.value,
|
|
108
|
+
tapTree: s.tapTree,
|
|
109
|
+
forfeitCb: s.forfeitTapLeafScript.cb,
|
|
110
|
+
forfeitS: s.forfeitTapLeafScript.s,
|
|
111
|
+
intentCb: s.intentTapLeafScript.cb,
|
|
112
|
+
intentS: s.intentTapLeafScript.s,
|
|
113
|
+
statusJson: JSON.stringify(s.status),
|
|
114
|
+
extraWitnessJson: s.extraWitness
|
|
115
|
+
? JSON.stringify(s.extraWitness)
|
|
116
|
+
: null,
|
|
117
|
+
}, "modified");
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async deleteUtxos(address) {
|
|
122
|
+
await this.ensureInit();
|
|
123
|
+
this.realm.write(() => {
|
|
124
|
+
const toDelete = this.realm
|
|
125
|
+
.objects("ArkUtxo")
|
|
126
|
+
.filtered("address == $0", address);
|
|
127
|
+
this.realm.delete(toDelete);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// ── Transaction history ────────────────────────────────────────────
|
|
131
|
+
async getTransactionHistory(address) {
|
|
132
|
+
await this.ensureInit();
|
|
133
|
+
const results = this.realm
|
|
134
|
+
.objects("ArkTransaction")
|
|
135
|
+
.filtered("address == $0", address);
|
|
136
|
+
const txs = [...results].map(txObjectToDomain);
|
|
137
|
+
txs.sort((a, b) => a.createdAt - b.createdAt);
|
|
138
|
+
return txs;
|
|
139
|
+
}
|
|
140
|
+
async saveTransactions(address, txs) {
|
|
141
|
+
await this.ensureInit();
|
|
142
|
+
this.realm.write(() => {
|
|
143
|
+
for (const tx of txs) {
|
|
144
|
+
this.realm.create("ArkTransaction", {
|
|
145
|
+
pk: `${address}:${tx.key.boardingTxid}:${tx.key.commitmentTxid}:${tx.key.arkTxid}`,
|
|
146
|
+
address,
|
|
147
|
+
boardingTxid: tx.key.boardingTxid,
|
|
148
|
+
commitmentTxid: tx.key.commitmentTxid,
|
|
149
|
+
arkTxid: tx.key.arkTxid,
|
|
150
|
+
type: tx.type,
|
|
151
|
+
amount: tx.amount,
|
|
152
|
+
settled: tx.settled,
|
|
153
|
+
createdAt: tx.createdAt,
|
|
154
|
+
assetsJson: tx.assets
|
|
155
|
+
? JSON.stringify(tx.assets)
|
|
156
|
+
: null,
|
|
157
|
+
}, "modified");
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
async deleteTransactions(address) {
|
|
162
|
+
await this.ensureInit();
|
|
163
|
+
this.realm.write(() => {
|
|
164
|
+
const toDelete = this.realm
|
|
165
|
+
.objects("ArkTransaction")
|
|
166
|
+
.filtered("address == $0", address);
|
|
167
|
+
this.realm.delete(toDelete);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// ── Wallet state ───────────────────────────────────────────────────
|
|
171
|
+
async getWalletState() {
|
|
172
|
+
await this.ensureInit();
|
|
173
|
+
const results = this.realm
|
|
174
|
+
.objects("ArkWalletState")
|
|
175
|
+
.filtered("key == $0", "state");
|
|
176
|
+
const items = [...results];
|
|
177
|
+
if (items.length === 0)
|
|
178
|
+
return null;
|
|
179
|
+
const obj = items[0];
|
|
180
|
+
const state = {};
|
|
181
|
+
if (obj.lastSyncTime !== null && obj.lastSyncTime !== undefined) {
|
|
182
|
+
state.lastSyncTime = obj.lastSyncTime;
|
|
183
|
+
}
|
|
184
|
+
if (obj.settingsJson) {
|
|
185
|
+
state.settings = JSON.parse(obj.settingsJson);
|
|
186
|
+
}
|
|
187
|
+
return state;
|
|
188
|
+
}
|
|
189
|
+
async saveWalletState(state) {
|
|
190
|
+
await this.ensureInit();
|
|
191
|
+
this.realm.write(() => {
|
|
192
|
+
this.realm.create("ArkWalletState", {
|
|
193
|
+
key: "state",
|
|
194
|
+
lastSyncTime: state.lastSyncTime ?? null,
|
|
195
|
+
settingsJson: state.settings
|
|
196
|
+
? JSON.stringify(state.settings)
|
|
197
|
+
: null,
|
|
198
|
+
}, "modified");
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.RealmWalletRepository = RealmWalletRepository;
|
|
203
|
+
// ── Realm object → Domain converters ─────────────────────────────────────
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
205
|
+
function vtxoObjectToDomain(obj) {
|
|
206
|
+
const serialized = {
|
|
207
|
+
txid: obj.txid,
|
|
208
|
+
vout: obj.vout,
|
|
209
|
+
value: obj.value,
|
|
210
|
+
tapTree: obj.tapTree,
|
|
211
|
+
forfeitTapLeafScript: {
|
|
212
|
+
cb: obj.forfeitCb,
|
|
213
|
+
s: obj.forfeitS,
|
|
214
|
+
},
|
|
215
|
+
intentTapLeafScript: {
|
|
216
|
+
cb: obj.intentCb,
|
|
217
|
+
s: obj.intentS,
|
|
218
|
+
},
|
|
219
|
+
status: JSON.parse(obj.statusJson),
|
|
220
|
+
virtualStatus: JSON.parse(obj.virtualStatusJson),
|
|
221
|
+
createdAt: new Date(obj.createdAt),
|
|
222
|
+
isUnrolled: obj.isUnrolled,
|
|
223
|
+
isSpent: obj.isSpent === null ? undefined : obj.isSpent,
|
|
224
|
+
spentBy: obj.spentBy ?? undefined,
|
|
225
|
+
settledBy: obj.settledBy ?? undefined,
|
|
226
|
+
arkTxId: obj.arkTxId ?? undefined,
|
|
227
|
+
extraWitness: obj.extraWitnessJson
|
|
228
|
+
? JSON.parse(obj.extraWitnessJson)
|
|
229
|
+
: undefined,
|
|
230
|
+
assets: obj.assetsJson ? JSON.parse(obj.assetsJson) : undefined,
|
|
231
|
+
};
|
|
232
|
+
return (0, serialization_1.deserializeVtxo)(serialized);
|
|
233
|
+
}
|
|
234
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
235
|
+
function utxoObjectToDomain(obj) {
|
|
236
|
+
const serialized = {
|
|
237
|
+
txid: obj.txid,
|
|
238
|
+
vout: obj.vout,
|
|
239
|
+
value: obj.value,
|
|
240
|
+
tapTree: obj.tapTree,
|
|
241
|
+
forfeitTapLeafScript: {
|
|
242
|
+
cb: obj.forfeitCb,
|
|
243
|
+
s: obj.forfeitS,
|
|
244
|
+
},
|
|
245
|
+
intentTapLeafScript: {
|
|
246
|
+
cb: obj.intentCb,
|
|
247
|
+
s: obj.intentS,
|
|
248
|
+
},
|
|
249
|
+
status: JSON.parse(obj.statusJson),
|
|
250
|
+
extraWitness: obj.extraWitnessJson
|
|
251
|
+
? JSON.parse(obj.extraWitnessJson)
|
|
252
|
+
: undefined,
|
|
253
|
+
};
|
|
254
|
+
return (0, serialization_1.deserializeUtxo)(serialized);
|
|
255
|
+
}
|
|
256
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
257
|
+
function txObjectToDomain(obj) {
|
|
258
|
+
const tx = {
|
|
259
|
+
key: {
|
|
260
|
+
boardingTxid: obj.boardingTxid,
|
|
261
|
+
commitmentTxid: obj.commitmentTxid,
|
|
262
|
+
arkTxid: obj.arkTxid,
|
|
263
|
+
},
|
|
264
|
+
type: obj.type,
|
|
265
|
+
amount: obj.amount,
|
|
266
|
+
settled: obj.settled,
|
|
267
|
+
createdAt: obj.createdAt,
|
|
268
|
+
};
|
|
269
|
+
if (obj.assetsJson) {
|
|
270
|
+
tx.assets = JSON.parse(obj.assetsJson);
|
|
271
|
+
}
|
|
272
|
+
return tx;
|
|
273
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeUtxo = exports.deserializeVtxo = exports.deserializeTapLeaf = exports.serializeUtxo = exports.serializeVtxo = exports.serializeTapLeaf = void 0;
|
|
4
|
+
const base_1 = require("@scure/base");
|
|
5
|
+
const btc_signer_1 = require("@scure/btc-signer");
|
|
6
|
+
const serializeTapLeaf = ([cb, s,]) => ({
|
|
7
|
+
cb: base_1.hex.encode(btc_signer_1.TaprootControlBlock.encode(cb)),
|
|
8
|
+
s: base_1.hex.encode(s),
|
|
9
|
+
});
|
|
10
|
+
exports.serializeTapLeaf = serializeTapLeaf;
|
|
11
|
+
const serializeVtxo = (v) => ({
|
|
12
|
+
...v,
|
|
13
|
+
tapTree: base_1.hex.encode(v.tapTree),
|
|
14
|
+
forfeitTapLeafScript: (0, exports.serializeTapLeaf)(v.forfeitTapLeafScript),
|
|
15
|
+
intentTapLeafScript: (0, exports.serializeTapLeaf)(v.intentTapLeafScript),
|
|
16
|
+
extraWitness: v.extraWitness?.map(base_1.hex.encode),
|
|
17
|
+
});
|
|
18
|
+
exports.serializeVtxo = serializeVtxo;
|
|
19
|
+
const serializeUtxo = (u) => ({
|
|
20
|
+
...u,
|
|
21
|
+
tapTree: base_1.hex.encode(u.tapTree),
|
|
22
|
+
forfeitTapLeafScript: (0, exports.serializeTapLeaf)(u.forfeitTapLeafScript),
|
|
23
|
+
intentTapLeafScript: (0, exports.serializeTapLeaf)(u.intentTapLeafScript),
|
|
24
|
+
extraWitness: u.extraWitness?.map(base_1.hex.encode),
|
|
25
|
+
});
|
|
26
|
+
exports.serializeUtxo = serializeUtxo;
|
|
27
|
+
const deserializeTapLeaf = (t) => {
|
|
28
|
+
const cb = btc_signer_1.TaprootControlBlock.decode(base_1.hex.decode(t.cb));
|
|
29
|
+
const s = base_1.hex.decode(t.s);
|
|
30
|
+
return [cb, s];
|
|
31
|
+
};
|
|
32
|
+
exports.deserializeTapLeaf = deserializeTapLeaf;
|
|
33
|
+
const deserializeVtxo = (o) => ({
|
|
34
|
+
...o,
|
|
35
|
+
createdAt: new Date(o.createdAt),
|
|
36
|
+
tapTree: base_1.hex.decode(o.tapTree),
|
|
37
|
+
forfeitTapLeafScript: (0, exports.deserializeTapLeaf)(o.forfeitTapLeafScript),
|
|
38
|
+
intentTapLeafScript: (0, exports.deserializeTapLeaf)(o.intentTapLeafScript),
|
|
39
|
+
extraWitness: o.extraWitness?.map(base_1.hex.decode),
|
|
40
|
+
});
|
|
41
|
+
exports.deserializeVtxo = deserializeVtxo;
|
|
42
|
+
const deserializeUtxo = (o) => ({
|
|
43
|
+
...o,
|
|
44
|
+
tapTree: base_1.hex.decode(o.tapTree),
|
|
45
|
+
forfeitTapLeafScript: (0, exports.deserializeTapLeaf)(o.forfeitTapLeafScript),
|
|
46
|
+
intentTapLeafScript: (0, exports.deserializeTapLeaf)(o.intentTapLeafScript),
|
|
47
|
+
extraWitness: o.extraWitness?.map(base_1.hex.decode),
|
|
48
|
+
});
|
|
49
|
+
exports.deserializeUtxo = deserializeUtxo;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SQLiteContractRepository = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* SQLite-based implementation of ContractRepository.
|
|
6
|
+
*
|
|
7
|
+
* Uses the SQLExecutor interface so consumers can plug in any SQLite driver
|
|
8
|
+
* (expo-sqlite, better-sqlite3, etc.).
|
|
9
|
+
*
|
|
10
|
+
* Tables are created lazily on first operation via `ensureInit()`.
|
|
11
|
+
* The consumer owns the SQLExecutor lifecycle — `[Symbol.asyncDispose]` is a no-op.
|
|
12
|
+
*/
|
|
13
|
+
class SQLiteContractRepository {
|
|
14
|
+
constructor(db, options) {
|
|
15
|
+
this.db = db;
|
|
16
|
+
this.version = 1;
|
|
17
|
+
this.initPromise = null;
|
|
18
|
+
this.prefix = sanitizePrefix(options?.prefix ?? "ark_");
|
|
19
|
+
this.table = `${this.prefix}contracts`;
|
|
20
|
+
}
|
|
21
|
+
// ── Lifecycle ──────────────────────────────────────────────────────
|
|
22
|
+
ensureInit() {
|
|
23
|
+
if (!this.initPromise) {
|
|
24
|
+
this.initPromise = this.init();
|
|
25
|
+
}
|
|
26
|
+
return this.initPromise;
|
|
27
|
+
}
|
|
28
|
+
async init() {
|
|
29
|
+
await this.db.run(`
|
|
30
|
+
CREATE TABLE IF NOT EXISTS ${this.table} (
|
|
31
|
+
script TEXT PRIMARY KEY,
|
|
32
|
+
address TEXT NOT NULL,
|
|
33
|
+
type TEXT NOT NULL,
|
|
34
|
+
state TEXT NOT NULL,
|
|
35
|
+
params_json TEXT NOT NULL,
|
|
36
|
+
created_at INTEGER NOT NULL,
|
|
37
|
+
expires_at INTEGER,
|
|
38
|
+
label TEXT,
|
|
39
|
+
metadata_json TEXT
|
|
40
|
+
)
|
|
41
|
+
`);
|
|
42
|
+
await this.db.run(`CREATE INDEX IF NOT EXISTS idx_${this.prefix}contracts_type ON ${this.table} (type)`);
|
|
43
|
+
await this.db.run(`CREATE INDEX IF NOT EXISTS idx_${this.prefix}contracts_state ON ${this.table} (state)`);
|
|
44
|
+
}
|
|
45
|
+
async [Symbol.asyncDispose]() {
|
|
46
|
+
// no-op — consumer owns the SQLExecutor lifecycle
|
|
47
|
+
}
|
|
48
|
+
// ── Clear ──────────────────────────────────────────────────────────
|
|
49
|
+
async clear() {
|
|
50
|
+
await this.ensureInit();
|
|
51
|
+
await this.db.run(`DELETE FROM ${this.table}`);
|
|
52
|
+
}
|
|
53
|
+
// ── Contract management ────────────────────────────────────────────
|
|
54
|
+
async getContracts(filter) {
|
|
55
|
+
await this.ensureInit();
|
|
56
|
+
const conditions = [];
|
|
57
|
+
const params = [];
|
|
58
|
+
if (filter) {
|
|
59
|
+
this.addFilterCondition(conditions, params, "script", filter.script);
|
|
60
|
+
this.addFilterCondition(conditions, params, "state", filter.state);
|
|
61
|
+
this.addFilterCondition(conditions, params, "type", filter.type);
|
|
62
|
+
}
|
|
63
|
+
let sql = `SELECT * FROM ${this.table}`;
|
|
64
|
+
if (conditions.length > 0) {
|
|
65
|
+
sql += ` WHERE ${conditions.join(" AND ")}`;
|
|
66
|
+
}
|
|
67
|
+
const rows = await this.db.all(sql, params);
|
|
68
|
+
return rows.map(contractRowToDomain);
|
|
69
|
+
}
|
|
70
|
+
async saveContract(contract) {
|
|
71
|
+
await this.ensureInit();
|
|
72
|
+
await this.db.run(`INSERT OR REPLACE INTO ${this.table}
|
|
73
|
+
(script, address, type, state, params_json,
|
|
74
|
+
created_at, expires_at, label, metadata_json)
|
|
75
|
+
VALUES (?, ?, ?, ?, ?,
|
|
76
|
+
?, ?, ?, ?)`, [
|
|
77
|
+
contract.script,
|
|
78
|
+
contract.address,
|
|
79
|
+
contract.type,
|
|
80
|
+
contract.state,
|
|
81
|
+
JSON.stringify(contract.params),
|
|
82
|
+
contract.createdAt,
|
|
83
|
+
contract.expiresAt ?? null,
|
|
84
|
+
contract.label ?? null,
|
|
85
|
+
contract.metadata ? JSON.stringify(contract.metadata) : null,
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
async deleteContract(script) {
|
|
89
|
+
await this.ensureInit();
|
|
90
|
+
await this.db.run(`DELETE FROM ${this.table} WHERE script = ?`, [
|
|
91
|
+
script,
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
// ── Helpers ─────────────────────────────────────────────────────────
|
|
95
|
+
addFilterCondition(conditions, params, column, value) {
|
|
96
|
+
if (value === undefined)
|
|
97
|
+
return;
|
|
98
|
+
if (Array.isArray(value)) {
|
|
99
|
+
if (value.length === 0)
|
|
100
|
+
return;
|
|
101
|
+
const placeholders = value.map(() => "?").join(", ");
|
|
102
|
+
conditions.push(`${column} IN (${placeholders})`);
|
|
103
|
+
params.push(...value);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
conditions.push(`${column} = ?`);
|
|
107
|
+
params.push(value);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.SQLiteContractRepository = SQLiteContractRepository;
|
|
112
|
+
// ── Row → Domain converter ──────────────────────────────────────────────
|
|
113
|
+
const SAFE_PREFIX = /^[a-zA-Z0-9_]+$/;
|
|
114
|
+
function sanitizePrefix(prefix) {
|
|
115
|
+
if (!SAFE_PREFIX.test(prefix)) {
|
|
116
|
+
throw new Error(`Invalid table prefix "${prefix}": only letters, digits, and underscores are allowed`);
|
|
117
|
+
}
|
|
118
|
+
return prefix;
|
|
119
|
+
}
|
|
120
|
+
function contractRowToDomain(row) {
|
|
121
|
+
const contract = {
|
|
122
|
+
script: row.script,
|
|
123
|
+
address: row.address,
|
|
124
|
+
type: row.type,
|
|
125
|
+
state: row.state,
|
|
126
|
+
params: JSON.parse(row.params_json),
|
|
127
|
+
createdAt: row.created_at,
|
|
128
|
+
};
|
|
129
|
+
if (row.expires_at !== null) {
|
|
130
|
+
contract.expiresAt = row.expires_at;
|
|
131
|
+
}
|
|
132
|
+
if (row.label !== null) {
|
|
133
|
+
contract.label = row.label;
|
|
134
|
+
}
|
|
135
|
+
if (row.metadata_json !== null) {
|
|
136
|
+
contract.metadata = JSON.parse(row.metadata_json);
|
|
137
|
+
}
|
|
138
|
+
return contract;
|
|
139
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SQLiteContractRepository = exports.SQLiteWalletRepository = void 0;
|
|
4
|
+
var walletRepository_1 = require("./walletRepository");
|
|
5
|
+
Object.defineProperty(exports, "SQLiteWalletRepository", { enumerable: true, get: function () { return walletRepository_1.SQLiteWalletRepository; } });
|
|
6
|
+
var contractRepository_1 = require("./contractRepository");
|
|
7
|
+
Object.defineProperty(exports, "SQLiteContractRepository", { enumerable: true, get: function () { return contractRepository_1.SQLiteContractRepository; } });
|