@dignetwork/dig-sdk 0.0.1-alpha.99 → 0.1.0

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 (162) hide show
  1. package/LICENSE +21 -7
  2. package/README.md +267 -0
  3. package/dist/adapters.cjs +315 -0
  4. package/dist/adapters.cjs.map +1 -0
  5. package/dist/adapters.d.cts +20 -0
  6. package/dist/adapters.d.ts +20 -0
  7. package/dist/adapters.js +306 -0
  8. package/dist/adapters.js.map +1 -0
  9. package/dist/dev-shim-Bgw8X2E9.d.cts +118 -0
  10. package/dist/dev-shim-Bgw8X2E9.d.ts +118 -0
  11. package/dist/dig-client-entry-BIzuZ7Rs.d.cts +263 -0
  12. package/dist/dig-client-entry-BIzuZ7Rs.d.ts +263 -0
  13. package/dist/dig-client.cjs +330 -0
  14. package/dist/dig-client.cjs.map +1 -0
  15. package/dist/dig-client.d.cts +1 -0
  16. package/dist/dig-client.d.ts +1 -0
  17. package/dist/dig-client.js +319 -0
  18. package/dist/dig-client.js.map +1 -0
  19. package/dist/index.cjs +754 -0
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.cts +192 -0
  22. package/dist/index.d.ts +192 -5
  23. package/dist/index.js +731 -19
  24. package/dist/index.js.map +1 -0
  25. package/dist/next.cjs +326 -0
  26. package/dist/next.cjs.map +1 -0
  27. package/dist/next.d.cts +23 -0
  28. package/dist/next.d.ts +23 -0
  29. package/dist/next.js +319 -0
  30. package/dist/next.js.map +1 -0
  31. package/dist/spend.cjs +14 -0
  32. package/dist/spend.cjs.map +1 -0
  33. package/dist/spend.d.cts +1 -0
  34. package/dist/spend.d.ts +1 -0
  35. package/dist/spend.js +3 -0
  36. package/dist/spend.js.map +1 -0
  37. package/dist/vite.cjs +338 -0
  38. package/dist/vite.cjs.map +1 -0
  39. package/dist/vite.d.cts +35 -0
  40. package/dist/vite.d.ts +35 -0
  41. package/dist/vite.js +332 -0
  42. package/dist/vite.js.map +1 -0
  43. package/package.json +87 -59
  44. package/vendor/PROVENANCE.md +102 -0
  45. package/vendor/dig_client.d.ts +150 -0
  46. package/vendor/dig_client.mjs +805 -0
  47. package/vendor/dig_client_bg.wasm +0 -0
  48. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +0 -163
  49. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +0 -1
  50. package/dist/DataIntegrityTree/DataIntegrityTree.js +0 -707
  51. package/dist/DataIntegrityTree/DataLayerError.d.ts +0 -6
  52. package/dist/DataIntegrityTree/DataLayerError.d.ts.map +0 -1
  53. package/dist/DataIntegrityTree/DataLayerError.js +0 -17
  54. package/dist/DataIntegrityTree/index.d.ts +0 -2
  55. package/dist/DataIntegrityTree/index.d.ts.map +0 -1
  56. package/dist/DataIntegrityTree/index.js +0 -17
  57. package/dist/DigNetwork/ContentServer.d.ts +0 -31
  58. package/dist/DigNetwork/ContentServer.d.ts.map +0 -1
  59. package/dist/DigNetwork/ContentServer.js +0 -176
  60. package/dist/DigNetwork/DigChallenge.d.ts +0 -82
  61. package/dist/DigNetwork/DigChallenge.d.ts.map +0 -1
  62. package/dist/DigNetwork/DigChallenge.js +0 -144
  63. package/dist/DigNetwork/DigNetwork.d.ts +0 -14
  64. package/dist/DigNetwork/DigNetwork.d.ts.map +0 -1
  65. package/dist/DigNetwork/DigNetwork.js +0 -169
  66. package/dist/DigNetwork/DigPeer.d.ts +0 -24
  67. package/dist/DigNetwork/DigPeer.d.ts.map +0 -1
  68. package/dist/DigNetwork/DigPeer.js +0 -118
  69. package/dist/DigNetwork/IncentiveServer.d.ts +0 -13
  70. package/dist/DigNetwork/IncentiveServer.d.ts.map +0 -1
  71. package/dist/DigNetwork/IncentiveServer.js +0 -76
  72. package/dist/DigNetwork/PropagationServer.d.ts +0 -81
  73. package/dist/DigNetwork/PropagationServer.d.ts.map +0 -1
  74. package/dist/DigNetwork/PropagationServer.js +0 -563
  75. package/dist/DigNetwork/index.d.ts +0 -4
  76. package/dist/DigNetwork/index.d.ts.map +0 -1
  77. package/dist/DigNetwork/index.js +0 -19
  78. package/dist/blockchain/DataStore.d.ts +0 -67
  79. package/dist/blockchain/DataStore.d.ts.map +0 -1
  80. package/dist/blockchain/DataStore.js +0 -413
  81. package/dist/blockchain/DataStoreSerializer.d.ts +0 -52
  82. package/dist/blockchain/DataStoreSerializer.d.ts.map +0 -1
  83. package/dist/blockchain/DataStoreSerializer.js +0 -109
  84. package/dist/blockchain/FullNodePeer.d.ts +0 -31
  85. package/dist/blockchain/FullNodePeer.d.ts.map +0 -1
  86. package/dist/blockchain/FullNodePeer.js +0 -295
  87. package/dist/blockchain/ServerCoin.d.ts +0 -29
  88. package/dist/blockchain/ServerCoin.d.ts.map +0 -1
  89. package/dist/blockchain/ServerCoin.js +0 -324
  90. package/dist/blockchain/Wallet.d.ts +0 -28
  91. package/dist/blockchain/Wallet.d.ts.map +0 -1
  92. package/dist/blockchain/Wallet.js +0 -253
  93. package/dist/blockchain/coins.d.ts +0 -6
  94. package/dist/blockchain/coins.d.ts.map +0 -1
  95. package/dist/blockchain/coins.js +0 -102
  96. package/dist/blockchain/index.d.ts +0 -8
  97. package/dist/blockchain/index.d.ts.map +0 -1
  98. package/dist/blockchain/index.js +0 -36
  99. package/dist/index.d.ts.map +0 -1
  100. package/dist/prompts.d.ts +0 -21
  101. package/dist/prompts.d.ts.map +0 -1
  102. package/dist/prompts.js +0 -149
  103. package/dist/types.d.ts +0 -64
  104. package/dist/types.d.ts.map +0 -1
  105. package/dist/types.js +0 -2
  106. package/dist/utils/ContentScanner.d.ts +0 -63
  107. package/dist/utils/ContentScanner.d.ts.map +0 -1
  108. package/dist/utils/ContentScanner.js +0 -175
  109. package/dist/utils/Environment.d.ts +0 -18
  110. package/dist/utils/Environment.d.ts.map +0 -1
  111. package/dist/utils/Environment.js +0 -85
  112. package/dist/utils/FileCache.d.ts +0 -11
  113. package/dist/utils/FileCache.d.ts.map +0 -1
  114. package/dist/utils/FileCache.js +0 -58
  115. package/dist/utils/FileTransfer.d.ts +0 -47
  116. package/dist/utils/FileTransfer.d.ts.map +0 -1
  117. package/dist/utils/FileTransfer.js +0 -209
  118. package/dist/utils/NconfManager.d.ts +0 -11
  119. package/dist/utils/NconfManager.d.ts.map +0 -1
  120. package/dist/utils/NconfManager.js +0 -56
  121. package/dist/utils/StoreArchiveManager.d.ts +0 -45
  122. package/dist/utils/StoreArchiveManager.d.ts.map +0 -1
  123. package/dist/utils/StoreArchiveManager.js +0 -153
  124. package/dist/utils/asyncPool.d.ts +0 -9
  125. package/dist/utils/asyncPool.d.ts.map +0 -1
  126. package/dist/utils/asyncPool.js +0 -23
  127. package/dist/utils/config.d.ts +0 -68
  128. package/dist/utils/config.d.ts.map +0 -1
  129. package/dist/utils/config.js +0 -223
  130. package/dist/utils/connectionUtils.d.ts +0 -10
  131. package/dist/utils/connectionUtils.d.ts.map +0 -1
  132. package/dist/utils/connectionUtils.js +0 -18
  133. package/dist/utils/credentialsUtils.d.ts +0 -8
  134. package/dist/utils/credentialsUtils.d.ts.map +0 -1
  135. package/dist/utils/credentialsUtils.js +0 -122
  136. package/dist/utils/directoryUtils.d.ts +0 -9
  137. package/dist/utils/directoryUtils.d.ts.map +0 -1
  138. package/dist/utils/directoryUtils.js +0 -110
  139. package/dist/utils/encryption.d.ts +0 -8
  140. package/dist/utils/encryption.d.ts.map +0 -1
  141. package/dist/utils/encryption.js +0 -55
  142. package/dist/utils/hashUtils.d.ts +0 -8
  143. package/dist/utils/hashUtils.d.ts.map +0 -1
  144. package/dist/utils/hashUtils.js +0 -44
  145. package/dist/utils/index.d.ts +0 -14
  146. package/dist/utils/index.d.ts.map +0 -1
  147. package/dist/utils/index.js +0 -29
  148. package/dist/utils/merkle.d.ts +0 -2
  149. package/dist/utils/merkle.d.ts.map +0 -1
  150. package/dist/utils/merkle.js +0 -28
  151. package/dist/utils/network.d.ts +0 -2
  152. package/dist/utils/network.d.ts.map +0 -1
  153. package/dist/utils/network.js +0 -54
  154. package/dist/utils/spinnerUtils.d.ts +0 -2
  155. package/dist/utils/spinnerUtils.d.ts.map +0 -1
  156. package/dist/utils/spinnerUtils.js +0 -47
  157. package/dist/utils/ssl.d.ts +0 -5
  158. package/dist/utils/ssl.d.ts.map +0 -1
  159. package/dist/utils/ssl.js +0 -50
  160. package/dist/utils/validationUtils.d.ts +0 -9
  161. package/dist/utils/validationUtils.d.ts.map +0 -1
  162. package/dist/utils/validationUtils.js +0 -55
@@ -1,28 +0,0 @@
1
- import { Buffer } from "buffer";
2
- import { Peer, Coin, CoinSpend } from "@dignetwork/datalayer-driver";
3
- export declare const DEFAULT_FEE_COIN_COST = 64000000;
4
- export declare class Wallet {
5
- private mnemonic;
6
- private walletName;
7
- private constructor();
8
- static load(walletName?: string, createOnUndefined?: boolean): Promise<Wallet>;
9
- getMnemonic(): string;
10
- static createNewWallet(walletName: string): Promise<string>;
11
- static importWallet(walletName: string, seed?: string): Promise<string>;
12
- static importWalletFromChia(walletName: string): Promise<string>;
13
- getMasterSecretKey(): Promise<Buffer>;
14
- getPublicSyntheticKey(): Promise<Buffer>;
15
- getPrivateSyntheticKey(): Promise<Buffer>;
16
- getOwnerPuzzleHash(): Promise<Buffer>;
17
- getOwnerPublicKey(): Promise<string>;
18
- static deleteWallet(walletName: string): Promise<boolean>;
19
- static listWallets(): Promise<string[]>;
20
- private static getWalletFromKeyring;
21
- private static saveWalletToKeyring;
22
- createKeyOwnershipSignature(nonce: string): Promise<string>;
23
- static verifyKeyOwnershipSignature(nonce: string, signature: string, publicKey: string): Promise<boolean>;
24
- selectUnspentCoins(peer: Peer, coinAmount: bigint, feeBigInt: bigint, omitCoins?: Coin[]): Promise<Coin[]>;
25
- static calculateFeeForCoinSpends(peer: Peer, coinSpends: CoinSpend[] | null): Promise<bigint>;
26
- static isCoinSpendable(peer: Peer, coinId: Buffer): Promise<boolean>;
27
- }
28
- //# sourceMappingURL=Wallet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Wallet.d.ts","sourceRoot":"","sources":["../../src/blockchain/Wallet.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EASL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,8BAA8B,CAAC;AAQtC,eAAO,MAAM,qBAAqB,WAAa,CAAC;AAOhD,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,UAAU,CAAS;IAE3B,OAAO;WAKa,IAAI,CACtB,UAAU,GAAE,MAAkB,EAC9B,iBAAiB,GAAE,OAAc,GAChC,OAAO,CAAC,MAAM,CAAC;IAsBX,WAAW,IAAI,MAAM;WAOR,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;WAMpD,YAAY,CAC9B,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC;WASE,oBAAoB,CACtC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC;IA6BL,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKrC,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC;IAMxC,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKzC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAMrC,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;WAK7B,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;WASlD,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;mBAU/B,oBAAoB;mBAcpB,mBAAmB;IAS3B,2BAA2B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;WAUpD,2BAA2B,CAC7C,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IASN,kBAAkB,CAC7B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,SAAS,GAAE,IAAI,EAAO,GACrB,OAAO,CAAC,IAAI,EAAE,CAAC;WA+EE,yBAAyB,CAC3C,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,GAC7B,OAAO,CAAC,MAAM,CAAC;WAIE,eAAe,CACjC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;CAWpB"}
@@ -1,253 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Wallet = exports.DEFAULT_FEE_COIN_COST = void 0;
30
- const bip39 = __importStar(require("bip39"));
31
- const chia_bls_1 = require("chia-bls");
32
- const bip39_1 = require("bip39");
33
- const NconfManager_1 = require("../utils/NconfManager");
34
- const prompts_1 = require("../prompts");
35
- const chia_wallet_1 = __importDefault(require("chia-wallet"));
36
- // @ts-ignore
37
- const chia_root_resolver_1 = require("chia-root-resolver");
38
- const chia_config_loader_1 = require("chia-config-loader");
39
- const encryption_1 = require("../utils/encryption");
40
- const buffer_1 = require("buffer");
41
- const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
42
- const config_1 = require("../utils/config");
43
- const FileCache_1 = require("../utils/FileCache");
44
- const config_2 = require("../utils/config");
45
- const path_1 = __importDefault(require("path"));
46
- const KEYRING_FILE = "keyring.json";
47
- const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
48
- exports.DEFAULT_FEE_COIN_COST = 64000000;
49
- class Wallet {
50
- constructor(mnemonic, walletName) {
51
- this.mnemonic = null;
52
- this.mnemonic = mnemonic;
53
- this.walletName = walletName;
54
- }
55
- static async load(walletName = "default", createOnUndefined = true) {
56
- const mnemonic = await Wallet.getWalletFromKeyring(walletName);
57
- if (mnemonic)
58
- return new Wallet(mnemonic, walletName);
59
- if (createOnUndefined) {
60
- const { action } = await (0, prompts_1.askForMnemonicAction)();
61
- let newMnemonic;
62
- if (action === "Provide") {
63
- newMnemonic = await Wallet.importWallet(walletName);
64
- }
65
- else if (action === "Generate") {
66
- newMnemonic = await Wallet.createNewWallet(walletName);
67
- }
68
- else if (action === "Import From Chia Client") {
69
- newMnemonic = await Wallet.importWalletFromChia(walletName);
70
- }
71
- else {
72
- throw new Error("Mnemonic seed phrase is required.");
73
- }
74
- return new Wallet(newMnemonic, walletName);
75
- }
76
- throw new Error("Wallet Not Found");
77
- }
78
- getMnemonic() {
79
- if (!this.mnemonic) {
80
- throw new Error("Mnemonic seed phrase is not loaded.");
81
- }
82
- return this.mnemonic;
83
- }
84
- static async createNewWallet(walletName) {
85
- const mnemonic = bip39.generateMnemonic(256);
86
- await Wallet.saveWalletToKeyring(walletName, mnemonic);
87
- return mnemonic;
88
- }
89
- static async importWallet(walletName, seed) {
90
- const mnemonic = seed || (await (0, prompts_1.askForMnemonicInput)()).providedMnemonic;
91
- if (!bip39.validateMnemonic(mnemonic)) {
92
- throw new Error("Provided mnemonic is invalid.");
93
- }
94
- await Wallet.saveWalletToKeyring(walletName, mnemonic);
95
- return mnemonic;
96
- }
97
- static async importWalletFromChia(walletName) {
98
- const chiaRoot = (0, chia_root_resolver_1.getChiaRoot)();
99
- const certificateFolderPath = `${chiaRoot}/config/ssl`;
100
- const config = (0, chia_config_loader_1.getChiaConfig)();
101
- const defaultWalletPort = config?.wallet?.rpc_port || 9256;
102
- const walletRpc = new chia_wallet_1.default({
103
- wallet_host: `https://127.0.0.1:${defaultWalletPort}`,
104
- certificate_folder_path: certificateFolderPath,
105
- });
106
- const fingerprintInfo = await walletRpc.getLoggedInFingerprint({});
107
- if (!fingerprintInfo?.success) {
108
- throw new Error("Could not get fingerprint");
109
- }
110
- const privateKeyInfo = await walletRpc.getPrivateKey({
111
- fingerprint: fingerprintInfo.fingerprint,
112
- });
113
- if (!privateKeyInfo?.success) {
114
- throw new Error("Could not get private key");
115
- }
116
- const mnemonic = privateKeyInfo?.private_key.seed;
117
- await Wallet.saveWalletToKeyring(walletName, mnemonic);
118
- return mnemonic;
119
- }
120
- async getMasterSecretKey() {
121
- const seed = (0, bip39_1.mnemonicToSeedSync)(this.getMnemonic());
122
- return buffer_1.Buffer.from(chia_bls_1.PrivateKey.fromSeed(seed).toHex(), "hex");
123
- }
124
- async getPublicSyntheticKey() {
125
- const master_sk = await this.getMasterSecretKey();
126
- const master_pk = (0, datalayer_driver_1.secretKeyToPublicKey)(master_sk);
127
- return (0, datalayer_driver_1.masterPublicKeyToWalletSyntheticKey)(master_pk);
128
- }
129
- async getPrivateSyntheticKey() {
130
- const master_sk = await this.getMasterSecretKey();
131
- return (0, datalayer_driver_1.masterSecretKeyToWalletSyntheticSecretKey)(master_sk);
132
- }
133
- async getOwnerPuzzleHash() {
134
- const master_sk = await this.getMasterSecretKey();
135
- const master_pk = (0, datalayer_driver_1.secretKeyToPublicKey)(master_sk);
136
- return (0, datalayer_driver_1.masterPublicKeyToFirstPuzzleHash)(master_pk);
137
- }
138
- async getOwnerPublicKey() {
139
- const ownerPuzzleHash = await this.getOwnerPuzzleHash();
140
- return (0, datalayer_driver_1.puzzleHashToAddress)(ownerPuzzleHash, "xch");
141
- }
142
- static async deleteWallet(walletName) {
143
- const nconfManager = new NconfManager_1.NconfManager(KEYRING_FILE);
144
- if (await nconfManager.configExists()) {
145
- await nconfManager.deleteConfigValue(walletName);
146
- return true;
147
- }
148
- return false;
149
- }
150
- static async listWallets() {
151
- const nconfManager = new NconfManager_1.NconfManager(KEYRING_FILE);
152
- if (!(await nconfManager.configExists())) {
153
- return [];
154
- }
155
- const config = nconfManager.getFullConfig();
156
- return Object.keys(config);
157
- }
158
- static async getWalletFromKeyring(walletName) {
159
- const nconfManager = new NconfManager_1.NconfManager(KEYRING_FILE);
160
- if (await nconfManager.configExists()) {
161
- const encryptedData = await nconfManager.getConfigValue(walletName);
162
- if (encryptedData) {
163
- return (0, encryption_1.decryptData)(encryptedData);
164
- }
165
- }
166
- return null;
167
- }
168
- static async saveWalletToKeyring(walletName, mnemonic) {
169
- const nconfManager = new NconfManager_1.NconfManager(KEYRING_FILE);
170
- const encryptedData = (0, encryption_1.encryptData)(mnemonic);
171
- await nconfManager.setConfigValue(walletName, encryptedData);
172
- }
173
- async createKeyOwnershipSignature(nonce) {
174
- const message = `Signing this message to prove ownership of key.\n\nNonce: ${nonce}`;
175
- const privateSyntheticKey = await this.getPrivateSyntheticKey();
176
- const signature = (0, datalayer_driver_1.signMessage)(buffer_1.Buffer.from(message, "utf-8"), privateSyntheticKey);
177
- return signature.toString("hex");
178
- }
179
- static async verifyKeyOwnershipSignature(nonce, signature, publicKey) {
180
- const message = `Signing this message to prove ownership of key.\n\nNonce: ${nonce}`;
181
- return (0, datalayer_driver_1.verifySignedMessage)(buffer_1.Buffer.from(signature, "hex"), buffer_1.Buffer.from(publicKey, "hex"), buffer_1.Buffer.from(message, "utf-8"));
182
- }
183
- async selectUnspentCoins(peer, coinAmount, feeBigInt, omitCoins = []) {
184
- const cache = new FileCache_1.FileCache(path_1.default.join(config_2.USER_DIR_PATH, "reserved_coins"));
185
- const ownerPuzzleHash = await this.getOwnerPuzzleHash();
186
- // Define a function to attempt selecting unspent coins
187
- const trySelectCoins = async () => {
188
- const now = Date.now();
189
- const omitCoinIds = omitCoins.map((coin) => (0, datalayer_driver_1.getCoinId)(coin).toString("hex"));
190
- // Update omitCoinIds with currently valid reserved coins
191
- const cachedReservedCoins = cache.getCachedKeys();
192
- cachedReservedCoins.forEach((coinId) => {
193
- const reservation = cache.get(coinId);
194
- if (reservation && reservation.expiry > now) {
195
- if (!omitCoinIds.includes(coinId)) {
196
- omitCoinIds.push(coinId);
197
- }
198
- }
199
- else {
200
- cache.delete(coinId);
201
- }
202
- });
203
- const coinsResp = await peer.getAllUnspentCoins(ownerPuzzleHash, config_1.MIN_HEIGHT, buffer_1.Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
204
- const unspentCoins = coinsResp.coins.filter((coin) => !omitCoinIds.includes((0, datalayer_driver_1.getCoinId)(coin).toString("hex")));
205
- const selectedCoins = (0, datalayer_driver_1.selectCoins)(unspentCoins, feeBigInt + coinAmount);
206
- return selectedCoins;
207
- };
208
- let selectedCoins = [];
209
- let retry = true;
210
- while (retry) {
211
- selectedCoins = await trySelectCoins();
212
- if (selectedCoins.length > 0) {
213
- // Coins have been successfully selected
214
- retry = false;
215
- }
216
- else {
217
- const now = Date.now();
218
- // Check if there are any valid cached reserved coins left
219
- const cachedReservedCoins = cache.getCachedKeys().filter((coinId) => {
220
- const reservation = cache.get(coinId);
221
- return reservation && reservation.expiry > now;
222
- });
223
- if (cachedReservedCoins.length > 0) {
224
- // Wait 10 seconds and try again
225
- console.log("No unspent coins available. Waiting 10 seconds...");
226
- await new Promise((resolve) => setTimeout(resolve, 10000));
227
- }
228
- else {
229
- // No unspent coins and no reserved coins
230
- throw new Error("No unspent coins available.");
231
- }
232
- }
233
- }
234
- // Reserve the selected coins
235
- selectedCoins.forEach((coin) => {
236
- const coinId = (0, datalayer_driver_1.getCoinId)(coin).toString("hex");
237
- cache.set(coinId, { coinId, expiry: Date.now() + CACHE_DURATION });
238
- });
239
- return selectedCoins;
240
- }
241
- static async calculateFeeForCoinSpends(peer, coinSpends) {
242
- return BigInt(1000000);
243
- }
244
- static async isCoinSpendable(peer, coinId) {
245
- try {
246
- return await peer.isCoinSpent(coinId, config_1.MIN_HEIGHT, buffer_1.Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
247
- }
248
- catch (error) {
249
- return false;
250
- }
251
- }
252
- }
253
- exports.Wallet = Wallet;
@@ -1,6 +0,0 @@
1
- import { Peer, Coin, CoinSpend } from "@dignetwork/datalayer-driver";
2
- export declare const DEFAULT_FEE_COIN_COST = 64000000;
3
- export declare const calculateFeeForCoinSpends: (peer: Peer, coinSpends: CoinSpend[] | null) => Promise<bigint>;
4
- export declare const selectUnspentCoins: (peer: Peer, coinAmount: bigint, feeBigInt: bigint, omitCoins?: Coin[], walletName?: string) => Promise<Coin[]>;
5
- export declare const isCoinSpendable: (peer: Peer, coinId: Buffer) => Promise<boolean>;
6
- //# sourceMappingURL=coins.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coins.d.ts","sourceRoot":"","sources":["../../src/blockchain/coins.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,8BAA8B,CAAC;AAMtC,eAAO,MAAM,qBAAqB,WAAa,CAAC;AAWhD,eAAO,MAAM,yBAAyB,SAC9B,IAAI,cACE,SAAS,EAAE,GAAG,IAAI,KAC7B,OAAO,CAAC,MAAM,CA4BhB,CAAC;AAEF,eAAO,MAAM,kBAAkB,SACvB,IAAI,cACE,MAAM,aACP,MAAM,cACN,IAAI,EAAE,eACL,MAAM,KACjB,OAAO,CAAC,IAAI,EAAE,CAoEhB,CAAC;AAGF,eAAO,MAAM,eAAe,SACpB,IAAI,UACF,MAAM,KACb,OAAO,CAAC,OAAO,CAWjB,CAAC"}
@@ -1,102 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isCoinSpendable = exports.selectUnspentCoins = exports.calculateFeeForCoinSpends = exports.DEFAULT_FEE_COIN_COST = void 0;
4
- const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
5
- const Wallet_1 = require("./Wallet");
6
- const config_1 = require("../utils/config");
7
- const FileCache_1 = require("../utils/FileCache");
8
- const Environment_1 = require("../utils/Environment");
9
- exports.DEFAULT_FEE_COIN_COST = 64000000;
10
- // Set cache expiration time (5 minutes)
11
- const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes in milliseconds
12
- const calculateFeeForCoinSpends = async (peer, coinSpends) => {
13
- return BigInt(1000000);
14
- /*
15
- if (coinSpends === null) {
16
- return BigInt(DEFAULT_FEE_COIN_COST) * BigInt(2);
17
- }
18
-
19
- console.log("Calculating fee for coin spends...");
20
- let costForCoinSpend = await getCost(coinSpends);
21
-
22
- if (costForCoinSpend < BigInt(5)) {
23
- costForCoinSpend = BigInt(5);
24
- }
25
-
26
- console.log(`Cost for coin spends: ${costForCoinSpend}`);
27
- // Confirm in around 60 seconds
28
- const mojosPerClvmCost = await peer.getFeeEstimate(BigInt(60));
29
-
30
- console.log(`Mojo per clvm cost: ${mojosPerClvmCost}`);
31
- // Multiply the total cost by 2 just to be extra safe
32
- const fee =
33
- (BigInt(DEFAULT_FEE_COIN_COST) + costForCoinSpend * mojosPerClvmCost) *
34
- BigInt(2);
35
-
36
- console.log(`Fee for coin spends: ${fee}`);
37
-
38
- return fee;
39
- */
40
- };
41
- exports.calculateFeeForCoinSpends = calculateFeeForCoinSpends;
42
- const selectUnspentCoins = async (peer, coinAmount, feeBigInt, omitCoins = [], walletName = "default") => {
43
- // Initialize the cache for reserved coins
44
- const cache = new FileCache_1.FileCache("reserved_coins");
45
- // Get all cached reserved coins
46
- const cachedReservedCoins = cache.getCachedKeys();
47
- // Filter expired reserved coins and omit valid reservations
48
- const now = Date.now();
49
- const omitCoinIds = omitCoins.map((coin) => (0, datalayer_driver_1.getCoinId)(coin).toString("hex"));
50
- const validReservedCoins = cachedReservedCoins.filter((coinId) => {
51
- const reservation = cache.get(coinId);
52
- if (reservation && reservation.expiry > now) {
53
- // Valid reservation, add to omit list
54
- omitCoinIds.push(coinId);
55
- return true;
56
- }
57
- else {
58
- // Reservation expired, remove it
59
- cache.delete(coinId);
60
- return false;
61
- }
62
- });
63
- // Fetch all unspent coins from the peer
64
- const wallet = await Wallet_1.Wallet.load(walletName);
65
- const ownerPuzzleHash = await wallet.getOwnerPuzzleHash();
66
- const coinsResp = await peer.getAllUnspentCoins(ownerPuzzleHash, config_1.MIN_HEIGHT, Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
67
- if (Environment_1.Environment.DEBUG) {
68
- console.log("Unspent Coins:", coinsResp); // Debugging
69
- }
70
- const unspentCoins = coinsResp.coins;
71
- // Filter out the omitted coins
72
- const filteredUnspentCoins = unspentCoins.filter((coin) => !omitCoinIds.includes((0, datalayer_driver_1.getCoinId)(coin).toString("hex")));
73
- if (Environment_1.Environment.DEBUG) {
74
- console.log("Unspent Coins after filtering:", filteredUnspentCoins); // Debugging
75
- }
76
- // Select coins needed for the transaction
77
- const selectedCoins = (0, datalayer_driver_1.selectCoins)(filteredUnspentCoins, feeBigInt + coinAmount);
78
- if (Environment_1.Environment.DEBUG) {
79
- console.log("Selected Coins:", selectedCoins); // Debugging
80
- }
81
- // If no coins are selected, throw an error
82
- if (selectedCoins.length === 0) {
83
- throw new Error("No unspent coins available.");
84
- }
85
- // Cache the selected coins as reserved for the next 5 minutes
86
- selectedCoins.forEach((coin) => {
87
- const coinId = (0, datalayer_driver_1.getCoinId)(coin).toString("hex");
88
- cache.set(coinId, { coinId, expiry: Date.now() + CACHE_DURATION });
89
- });
90
- return selectedCoins;
91
- };
92
- exports.selectUnspentCoins = selectUnspentCoins;
93
- const isCoinSpendable = async (peer, coinId) => {
94
- try {
95
- const spent = await peer.isCoinSpent(coinId, config_1.MIN_HEIGHT, Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
96
- return spent;
97
- }
98
- catch (error) {
99
- return false;
100
- }
101
- };
102
- exports.isCoinSpendable = isCoinSpendable;
@@ -1,8 +0,0 @@
1
- export * from '../utils/FileCache';
2
- export * as coins from './coins';
3
- export * from './DataStore';
4
- export * from './FullNodePeer';
5
- export * from './DataStoreSerializer';
6
- export * from './ServerCoin';
7
- export * from "./Wallet";
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/blockchain/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAa,gBAAgB,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
@@ -1,36 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
- };
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.coins = void 0;
30
- __exportStar(require("../utils/FileCache"), exports);
31
- exports.coins = __importStar(require("./coins"));
32
- __exportStar(require("./DataStore"), exports);
33
- __exportStar(require("./FullNodePeer"), exports);
34
- __exportStar(require("./DataStoreSerializer"), exports);
35
- __exportStar(require("./ServerCoin"), exports);
36
- __exportStar(require("./Wallet"), exports);
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC"}
package/dist/prompts.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { CreateStoreUserInputs } from "./types";
2
- export declare const askForStoreDetails: (inputs?: CreateStoreUserInputs) => Promise<CreateStoreUserInputs>;
3
- export declare const askToDeleteAndReinit: () => Promise<boolean>;
4
- /**
5
- * Prompts the user to select an action (Provide, Generate, or Import).
6
- *
7
- * @returns {Promise<{ action: string }>} The action selected by the user.
8
- */
9
- export declare const askForMnemonicAction: () => Promise<{
10
- action: string;
11
- }>;
12
- /**
13
- * Prompts the user to input a mnemonic seed phrase and validates it.
14
- *
15
- * @returns {Promise<{ providedMnemonic: string }>} The mnemonic provided by the user.
16
- */
17
- export declare const askForMnemonicInput: () => Promise<{
18
- providedMnemonic: string;
19
- }>;
20
- export declare const promptForRemote: () => Promise<string>;
21
- //# sourceMappingURL=prompts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,kBAAkB,YACrB,qBAAqB,KAC5B,OAAO,CAAC,qBAAqB,CAkD/B,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAa,OAAO,CAAC,OAAO,CAa5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,QAAa,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAYvE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAa,OAAO,CAAC;IAAE,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAahF,CAAC;AAWF,eAAO,MAAM,eAAe,QAAa,OAAO,CAAC,MAAM,CAYtD,CAAC"}
package/dist/prompts.js DELETED
@@ -1,149 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.promptForRemote = exports.askForMnemonicInput = exports.askForMnemonicAction = exports.askToDeleteAndReinit = exports.askForStoreDetails = void 0;
30
- const inquirer_1 = __importDefault(require("inquirer"));
31
- const bip39 = __importStar(require("bip39"));
32
- const askForStoreDetails = async (inputs = {}) => {
33
- const questions = [];
34
- if (!inputs.label) {
35
- questions.push({
36
- type: "input",
37
- name: "label",
38
- message: "Enter the label for the data layer store:",
39
- validate: (input) => input.trim().length > 0 || "Label is required.",
40
- });
41
- }
42
- else if (inputs.label.trim().length === 0) {
43
- throw new Error("Label is required.");
44
- }
45
- if (!inputs.description) {
46
- questions.push({
47
- type: "input",
48
- name: "description",
49
- message: "Enter a description for the data layer store (max 50 chars):",
50
- validate: (input) => input.trim().length <= 50 || "Description must be 50 characters or less.",
51
- });
52
- }
53
- else if (inputs.description.trim().length > 50) {
54
- throw new Error("Description must be 50 characters or less.");
55
- }
56
- if (!inputs.authorizedWriter) {
57
- questions.push({
58
- type: "input",
59
- name: "authorizedWriter",
60
- message: "Enter the authorized writer public address (optional):",
61
- default: undefined,
62
- });
63
- }
64
- if (inputs.oracleFee === undefined) {
65
- questions.push({
66
- type: "input",
67
- name: "oracleFee",
68
- message: "Enter the oracle fee, in Mojos (optional, default is 100000):",
69
- default: 100000,
70
- filter: (input) => parseInt(input, 10),
71
- validate: (input) => !isNaN(parseInt(input, 10)) || "Oracle fee must be a number.",
72
- });
73
- }
74
- else if (isNaN(inputs.oracleFee)) {
75
- throw new Error("Oracle fee must be a number.");
76
- }
77
- const answers = await inquirer_1.default.prompt(questions);
78
- return { ...inputs, ...answers };
79
- };
80
- exports.askForStoreDetails = askForStoreDetails;
81
- const askToDeleteAndReinit = async () => {
82
- const questions = [
83
- {
84
- type: "confirm",
85
- name: "shouldDelete",
86
- message: "The .dig folder already exists. Do you want to delete it and re-init? This process is irreversible.",
87
- default: false,
88
- },
89
- ];
90
- const { shouldDelete } = await inquirer_1.default.prompt(questions);
91
- return shouldDelete;
92
- };
93
- exports.askToDeleteAndReinit = askToDeleteAndReinit;
94
- /**
95
- * Prompts the user to select an action (Provide, Generate, or Import).
96
- *
97
- * @returns {Promise<{ action: string }>} The action selected by the user.
98
- */
99
- const askForMnemonicAction = async () => {
100
- const questions = [
101
- {
102
- type: "list",
103
- name: "action",
104
- message: "No mnemonic seed found. Would you like to provide, generate, or import one?",
105
- choices: ["Provide", "Generate", "Import From Chia Client"],
106
- },
107
- ];
108
- const answers = await inquirer_1.default.prompt(questions);
109
- return answers;
110
- };
111
- exports.askForMnemonicAction = askForMnemonicAction;
112
- /**
113
- * Prompts the user to input a mnemonic seed phrase and validates it.
114
- *
115
- * @returns {Promise<{ providedMnemonic: string }>} The mnemonic provided by the user.
116
- */
117
- const askForMnemonicInput = async () => {
118
- const questions = [
119
- {
120
- type: "input",
121
- name: "providedMnemonic",
122
- message: "Please enter your mnemonic seed phrase:",
123
- validate: (input) => bip39.validateMnemonic(input) ? true : "Invalid mnemonic phrase. Please try again.",
124
- },
125
- ];
126
- const answers = await inquirer_1.default.prompt(questions);
127
- return answers;
128
- };
129
- exports.askForMnemonicInput = askForMnemonicInput;
130
- const hostPattern = /^[a-zA-Z0-9.-]+(:[0-9]{1,5})?$/;
131
- const validateHost = (input) => {
132
- if (hostPattern.test(input)) {
133
- return true;
134
- }
135
- return 'Please enter a valid host (e.g., example.com or example.com:8080)';
136
- };
137
- const promptForRemote = async () => {
138
- const questions = [
139
- {
140
- type: 'input',
141
- name: 'remoteHost',
142
- message: 'Please enter the remote peer ip:',
143
- validate: validateHost,
144
- },
145
- ];
146
- const answers = await inquirer_1.default.prompt(questions);
147
- return answers.remoteHost;
148
- };
149
- exports.promptForRemote = promptForRemote;