@dignetwork/dig-sdk 0.0.1-alpha.55 → 0.0.1-alpha.57

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.
@@ -1 +1 @@
1
- {"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,qBAAa,iBAAiB;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;IAGpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAYrB;gBAEU,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAY9C;;OAEG;IACG,gBAAgB;IAKtB;;OAEG;IACH,gBAAgB;IAQhB;;;;;OAKG;IACG,gBAAgB,CACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IA4C7D;;OAEG;IACG,kBAAkB;IAqCxB;;OAEG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBrD;;;OAGG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM;IAuDjC;;;;;;OAMG;WACU,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;IAyCnB;;;;;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ACU,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;IAyCnB;;;;;OAKG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4ClD;;;;OAIG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM;IAkEnC;;;;;OAKG;WACU,aAAa,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;CA4BpB"}
@@ -14,9 +14,9 @@ const credentialsUtils_1 = require("../utils/credentialsUtils");
14
14
  const https_1 = __importDefault(require("https"));
15
15
  const cli_progress_1 = __importDefault(require("cli-progress"));
16
16
  const colorette_1 = require("colorette"); // For colored output
17
- const ora_1 = __importDefault(require("ora")); // For spinners
18
17
  const config_1 = require("../utils/config");
19
18
  const hashUtils_1 = require("../utils/hashUtils");
19
+ const nanospinner_1 = require("nanospinner");
20
20
  class PropagationServer {
21
21
  constructor(storeId, ipAddress) {
22
22
  this.storeId = storeId;
@@ -33,7 +33,7 @@ class PropagationServer {
33
33
  */
34
34
  async initializeWallet() {
35
35
  this.wallet = await blockchain_1.Wallet.load("default");
36
- this.publicKey = await this.wallet.getPrivateSyntheticKey();
36
+ this.publicKey = await this.wallet.getPublicSyntheticKey().toString('hex');
37
37
  }
38
38
  /**
39
39
  * Create an Axios HTTPS Agent with self-signed certificate allowance.
@@ -52,12 +52,12 @@ class PropagationServer {
52
52
  * @returns {Promise<{ storeExists: boolean, rootHashExists: boolean }>} - An object indicating if the store and root hash exist.
53
53
  */
54
54
  async checkStoreExists(rootHash) {
55
- const spinner = (0, ora_1.default)(`Checking if store ${this.storeId} exists...`).start();
55
+ const spinner = (0, nanospinner_1.createSpinner)(`Checking if store ${this.storeId} exists...`).start();
56
56
  try {
57
57
  const config = {
58
58
  httpsAgent: this.createHttpsAgent(),
59
59
  };
60
- let url = `https://${this.ipAddress}:${PropagationServer.port}/stores/${this.storeId}`;
60
+ let url = `https://${this.ipAddress}:${PropagationServer.port}/${this.storeId}`;
61
61
  if (rootHash) {
62
62
  url += `?hasRootHash=${rootHash}`;
63
63
  }
@@ -66,10 +66,10 @@ class PropagationServer {
66
66
  const storeExists = response.headers["x-store-exists"] === "true";
67
67
  const rootHashExists = response.headers["x-has-root-hash"] === "true";
68
68
  if (storeExists) {
69
- spinner.succeed((0, colorette_1.green)(`Store ${this.storeId} exists!`));
69
+ spinner.success({ text: (0, colorette_1.green)(`Store ${this.storeId} exists on peer!`) });
70
70
  }
71
71
  else {
72
- spinner.fail((0, colorette_1.red)(`Store ${this.storeId} does not exist.`));
72
+ spinner.error({ text: (0, colorette_1.red)(`Store ${this.storeId} does not exist. Credentials will be required to push.`) });
73
73
  }
74
74
  if (rootHash) {
75
75
  if (rootHashExists) {
@@ -82,8 +82,8 @@ class PropagationServer {
82
82
  return { storeExists, rootHashExists };
83
83
  }
84
84
  catch (error) {
85
- spinner.fail((0, colorette_1.red)("Error checking if store exists:"));
86
- console.error((0, colorette_1.red)(error));
85
+ spinner.error({ text: (0, colorette_1.red)("Error checking if store exists:") });
86
+ console.error((0, colorette_1.red)(error.message));
87
87
  throw error;
88
88
  }
89
89
  }
@@ -91,7 +91,7 @@ class PropagationServer {
91
91
  * Start an upload session by sending a POST request to the server.
92
92
  */
93
93
  async startUploadSession() {
94
- const spinner = (0, ora_1.default)(`Starting upload session for store ${this.storeId}...`).start();
94
+ const spinner = (0, nanospinner_1.createSpinner)(`Starting upload session for store ${this.storeId}...`).start();
95
95
  try {
96
96
  const config = {
97
97
  httpsAgent: this.createHttpsAgent(),
@@ -106,11 +106,13 @@ class PropagationServer {
106
106
  const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}`;
107
107
  const response = await axios_1.default.post(url, { publicKey: this.publicKey }, config);
108
108
  this.sessionId = response.data.sessionId;
109
- spinner.succeed((0, colorette_1.green)(`Upload session started for DataStore ${this.storeId} with session ID ${this.sessionId}`));
109
+ spinner.success({
110
+ text: (0, colorette_1.green)(`Upload session started for DataStore ${this.storeId} with session ID ${this.sessionId}`),
111
+ });
110
112
  }
111
113
  catch (error) {
112
- spinner.fail((0, colorette_1.red)("Error starting upload session:"));
113
- console.error((0, colorette_1.red)(error));
114
+ spinner.error({ text: (0, colorette_1.red)("Error starting upload session:") });
115
+ console.error((0, colorette_1.red)(error.message));
114
116
  throw error;
115
117
  }
116
118
  }
@@ -129,7 +131,7 @@ class PropagationServer {
129
131
  return nonce;
130
132
  }
131
133
  catch (error) {
132
- console.error((0, colorette_1.red)(`Error generating nonce for file ${filename}:`), error);
134
+ console.error((0, colorette_1.red)(`Error generating nonce for file ${filename}:`), error.message);
133
135
  throw error;
134
136
  }
135
137
  }
@@ -140,7 +142,9 @@ class PropagationServer {
140
142
  async uploadFile(filePath) {
141
143
  const filename = path_1.default.basename(filePath);
142
144
  const nonce = await this.getFileNonce(filename);
143
- const keyOwnershipSig = await this.wallet.createKeyOwnershipSignature(nonce);
145
+ const wallet = await blockchain_1.Wallet.load("default");
146
+ const keyOwnershipSig = await wallet.createKeyOwnershipSignature(nonce);
147
+ const publicKey = await wallet.getPublicSyntheticKey();
144
148
  const formData = new form_data_1.default();
145
149
  formData.append("file", fs_1.default.createReadStream(filePath));
146
150
  const fileSize = fs_1.default.statSync(filePath).size;
@@ -154,7 +158,7 @@ class PropagationServer {
154
158
  headers: {
155
159
  "Content-Type": "multipart/form-data",
156
160
  "x-nonce": nonce,
157
- "x-public-key": this.publicKey,
161
+ "x-public-key": publicKey.toString("hex"),
158
162
  "x-key-ownership-sig": keyOwnershipSig,
159
163
  ...formData.getHeaders(),
160
164
  },
@@ -176,7 +180,7 @@ class PropagationServer {
176
180
  return response.data;
177
181
  }
178
182
  catch (error) {
179
- console.error((0, colorette_1.red)(`✖ Error uploading file ${filename}:`), error);
183
+ console.error((0, colorette_1.red)(`✖ Error uploading file ${filename}:`), error.message);
180
184
  progressBar.stop(); // Stop the progress bar in case of error
181
185
  throw error;
182
186
  }
@@ -20,7 +20,7 @@ export declare class Wallet {
20
20
  private static getWalletFromKeyring;
21
21
  private static saveWalletToKeyring;
22
22
  createKeyOwnershipSignature(nonce: string): Promise<string>;
23
- verifyKeyOwnershipSignature(nonce: string, signature: string, publicKey: string): Promise<boolean>;
23
+ static verifyKeyOwnershipSignature(nonce: string, signature: string, publicKey: string): Promise<boolean>;
24
24
  selectUnspentCoins(peer: Peer, coinAmount: bigint, feeBigInt: bigint, omitCoins?: Coin[]): Promise<Coin[]>;
25
25
  static calculateFeeForCoinSpends(peer: Peer, coinSpends: CoinSpend[] | null): Promise<bigint>;
26
26
  static isCoinSpendable(peer: Peer, coinId: Buffer): Promise<boolean>;
@@ -1 +1 @@
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;AAMtC,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,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;WAShE,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA6BhE,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKrC,qBAAqB,IAAI,OAAO,CAAC,MAAM,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@@ -174,7 +174,7 @@ class Wallet {
174
174
  const signature = (0, datalayer_driver_1.signMessage)(buffer_1.Buffer.from(message, "utf-8"), privateSyntheticKey);
175
175
  return signature.toString("hex");
176
176
  }
177
- async verifyKeyOwnershipSignature(nonce, signature, publicKey) {
177
+ static async verifyKeyOwnershipSignature(nonce, signature, publicKey) {
178
178
  const message = `Signing this message to prove ownership of key.\n\nNonce: ${nonce}`;
179
179
  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"));
180
180
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.55",
3
+ "version": "0.0.1-alpha.57",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",
@@ -46,7 +46,6 @@
46
46
  "nanospinner": "^1.1.0",
47
47
  "nconf": "^0.12.1",
48
48
  "node-cache": "^5.1.2",
49
- "ora": "^8.1.0",
50
49
  "p-limit": "^6.1.0",
51
50
  "superagent": "^10.0.0",
52
51
  "unzipper": "^0.12.3"