phantasma-sdk-ts 0.2.7 → 0.2.9

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 (43) hide show
  1. package/README.md +11 -0
  2. package/dist/cjs/core/ledger/Ledger-Commands.js +23 -22
  3. package/dist/cjs/core/ledger/Ledger-Utils.js +36 -35
  4. package/dist/cjs/core/ledger/Transaction-Sign.js +16 -15
  5. package/dist/cjs/core/link/easyConnect.js +15 -14
  6. package/dist/cjs/core/link/phantasmaLink.js +4 -3
  7. package/dist/cjs/core/rpc/phantasma.js +7 -6
  8. package/dist/cjs/core/tx/Transaction.js +8 -7
  9. package/dist/cjs/core/types/Address.js +3 -3
  10. package/dist/cjs/core/types/Carbon/Blockchain/Modules/Builders/TokenSchemasBuilder.js +2 -1
  11. package/dist/cjs/core/utils/Hex.js +13 -6
  12. package/dist/cjs/core/utils/index.js +1 -0
  13. package/dist/cjs/core/utils/logger.js +23 -0
  14. package/dist/cjs/core/vm/Decoder.js +4 -3
  15. package/dist/esm/core/ledger/Ledger-Commands.js +23 -22
  16. package/dist/esm/core/ledger/Ledger-Utils.js +36 -35
  17. package/dist/esm/core/ledger/Transaction-Sign.js +16 -15
  18. package/dist/esm/core/link/easyConnect.js +15 -14
  19. package/dist/esm/core/link/phantasmaLink.js +4 -3
  20. package/dist/esm/core/rpc/phantasma.js +7 -6
  21. package/dist/esm/core/tx/Transaction.js +6 -5
  22. package/dist/esm/core/types/Address.js +2 -2
  23. package/dist/esm/core/types/Carbon/Blockchain/Modules/Builders/TokenSchemasBuilder.js +2 -1
  24. package/dist/esm/core/utils/Hex.js +13 -6
  25. package/dist/esm/core/utils/index.js +1 -0
  26. package/dist/esm/core/utils/logger.js +19 -0
  27. package/dist/esm/core/vm/Decoder.js +4 -3
  28. package/dist/esm/package.json +1 -0
  29. package/dist/types/core/ledger/Ledger-Commands.d.ts.map +1 -1
  30. package/dist/types/core/ledger/Ledger-Utils.d.ts.map +1 -1
  31. package/dist/types/core/ledger/Transaction-Sign.d.ts.map +1 -1
  32. package/dist/types/core/link/easyConnect.d.ts.map +1 -1
  33. package/dist/types/core/link/phantasmaLink.d.ts.map +1 -1
  34. package/dist/types/core/rpc/phantasma.d.ts.map +1 -1
  35. package/dist/types/core/tx/Transaction.d.ts.map +1 -1
  36. package/dist/types/core/types/Carbon/Blockchain/Modules/Builders/TokenSchemasBuilder.d.ts.map +1 -1
  37. package/dist/types/core/utils/Hex.d.ts.map +1 -1
  38. package/dist/types/core/utils/index.d.ts +1 -0
  39. package/dist/types/core/utils/index.d.ts.map +1 -1
  40. package/dist/types/core/utils/logger.d.ts +11 -0
  41. package/dist/types/core/utils/logger.d.ts.map +1 -0
  42. package/dist/types/core/vm/Decoder.d.ts.map +1 -1
  43. package/package.json +4 -3
package/README.md CHANGED
@@ -16,6 +16,17 @@ npm install phantasma-sdk-ts
16
16
  const { PhantasmaTS } = require("phantasma-sdk-ts");
17
17
  ```
18
18
 
19
+ ## Logging
20
+
21
+ SDK logging is opt-in. To enable logs, pass your logger (for example, `console`) to `setLogger`. Leave it unset for silent operation.
22
+
23
+ ```javascript
24
+ const { setLogger } = require("phantasma-sdk-ts");
25
+
26
+ setLogger(console); // enable SDK logs
27
+ // setLogger(); // disable SDK logs
28
+ ```
29
+
19
30
  ## Standalone HTML Import
20
31
 
21
32
  ```html
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetBalanceFromMnemonic = exports.GetBalanceFromPrivateKey = exports.SendTransactionLedger = exports.GetAddressFromLedeger = exports.GetBalanceFromLedger = exports.GetLedgerSignerData = exports.GetLedgerAccountSigner = exports.GetLedgerDeviceInfo = exports.ToWholeNumber = exports.LeftPad = void 0;
4
4
  const index_js_1 = require("../index.js");
5
+ const logger_js_1 = require("../utils/logger.js");
5
6
  const index_js_2 = require("../tx/index.js");
6
7
  const index_js_3 = require("../types/index.js");
7
8
  const Address_Transcode_js_1 = require("./Address-Transcode.js");
@@ -80,7 +81,7 @@ const GetLedgerAccountSigner = async (config, accountIx) => {
80
81
  throw Error('accountIx is a required parameter.');
81
82
  }
82
83
  const paths = await config.Transport.list();
83
- console.log('paths', paths);
84
+ logger_js_1.logger.log('paths', paths);
84
85
  if (paths.length == 0) {
85
86
  alert('NUmber of devices found:' + paths.length);
86
87
  return;
@@ -152,7 +153,7 @@ const GetBalanceFromLedger = async (config, options) => {
152
153
  const msg = await (0, Ledger_Utils_js_1.GetPublicKey)(config.Transport, options);
153
154
  /* istanbul ignore if */
154
155
  if (config.Debug) {
155
- console.log('getBalanceFromLedger', 'msg', msg);
156
+ logger_js_1.logger.log('getBalanceFromLedger', 'msg', msg);
156
157
  }
157
158
  let response = {
158
159
  address: index_js_3.Address.Null,
@@ -169,13 +170,13 @@ const GetBalanceFromLedger = async (config, options) => {
169
170
  const address = (0, Address_Transcode_js_1.GetAddressPublicKeyFromPublicKey)(publicKey);
170
171
  /* istanbul ignore if */
171
172
  if (config.Debug) {
172
- console.log('address', address);
173
- console.log('rpc', config.RPC);
173
+ logger_js_1.logger.log('address', address);
174
+ logger_js_1.logger.log('rpc', config.RPC);
174
175
  }
175
- console.log('rpcAwait', await config.RPC.getAccount(address.Text));
176
+ logger_js_1.logger.log('rpcAwait', await config.RPC.getAccount(address.Text));
176
177
  const rpcResponse = await config.RPC.getAccount(address.Text);
177
178
  if (config.Debug) {
178
- console.log('rpcResponse', rpcResponse);
179
+ logger_js_1.logger.log('rpcResponse', rpcResponse);
179
180
  }
180
181
  response.balances = new Map();
181
182
  if (rpcResponse.balances !== undefined) {
@@ -207,7 +208,7 @@ const GetAddressFromLedeger = async (config, options) => {
207
208
  const msg = await (0, Ledger_Utils_js_1.GetPublicKey)(config.Transport, options);
208
209
  /* istanbul ignore if */
209
210
  if (config.Debug) {
210
- console.log('getBalanceFromLedger', 'msg', msg);
211
+ logger_js_1.logger.log('getBalanceFromLedger', 'msg', msg);
211
212
  }
212
213
  if (msg.success) {
213
214
  const publicKey = msg.publicKey;
@@ -229,7 +230,7 @@ async function SignEncodedTx(encodedTx, config) {
229
230
  const response = await (0, Ledger_Utils_js_1.SignLedger)(config.Transport, encodedTx);
230
231
  /* istanbul ignore if */
231
232
  if (config.Debug) {
232
- console.log('sendAmountUsingLedger', 'signCallback', 'response', response);
233
+ logger_js_1.logger.log('sendAmountUsingLedger', 'signCallback', 'response', response);
233
234
  }
234
235
  if (response.success) {
235
236
  return response.signature;
@@ -252,7 +253,7 @@ async function SendTransactionLedger(config, script) {
252
253
  const msg_publicKey = await (0, Ledger_Utils_js_1.GetPublicKey)(config.Transport, options);
253
254
  if (!msg_publicKey.success) {
254
255
  if (config.Debug) {
255
- console.log('SendTransactionLedger', 'error ', msg_publicKey);
256
+ logger_js_1.logger.log('SendTransactionLedger', 'error ', msg_publicKey);
256
257
  }
257
258
  return msg_publicKey;
258
259
  }
@@ -273,11 +274,11 @@ async function SendTransactionLedger(config, script) {
273
274
  const encodedTx = index_js_3.Base16.encodeUint8Array(myTransaction.ToByteAray(false));
274
275
  try {
275
276
  if (config.Debug) {
276
- console.log('sendAmountUsingCallback', 'encodedTx', encodedTx);
277
+ logger_js_1.logger.log('sendAmountUsingCallback', 'encodedTx', encodedTx);
277
278
  }
278
279
  const signature = await SignEncodedTx(encodedTx, config);
279
280
  if (config.Debug) {
280
- console.log('sendAmountUsingCallback', 'signature', signature);
281
+ logger_js_1.logger.log('sendAmountUsingCallback', 'signature', signature);
281
282
  }
282
283
  if (config.VerifyResponse) {
283
284
  const verifyResponse = (0, Transaction_Sign_js_1.Verify)(encodedTx, signature, publicKey);
@@ -285,7 +286,7 @@ async function SendTransactionLedger(config, script) {
285
286
  throw Error(`invalidSignature encodedTx:'${encodedTx}', publicKey:'${publicKey}' signature:'${signature}'`);
286
287
  }
287
288
  if (config.Debug) {
288
- console.log('verifyResponse', verifyResponse);
289
+ logger_js_1.logger.log('verifyResponse', verifyResponse);
289
290
  }
290
291
  }
291
292
  let signatureBytes = index_js_3.Base16.decodeUint8Array(signature);
@@ -294,13 +295,13 @@ async function SendTransactionLedger(config, script) {
294
295
  myNewSignaturesArray.push(mySignature);
295
296
  myTransaction.signatures = myNewSignaturesArray;
296
297
  if (config.Debug) {
297
- console.log('signedTx', myTransaction);
298
+ logger_js_1.logger.log('signedTx', myTransaction);
298
299
  }
299
300
  const encodedSignedTx = index_js_3.Base16.encodeUint8Array(myTransaction.ToByteAray(true));
300
- console.log('encoded signed tx: ', encodedSignedTx);
301
+ logger_js_1.logger.log('encoded signed tx: ', encodedSignedTx);
301
302
  const txHash = await config.RPC.sendRawTransaction(encodedSignedTx);
302
303
  if (config.Debug) {
303
- console.log('sendAmountUsingCallback', 'txHash', txHash);
304
+ logger_js_1.logger.log('sendAmountUsingCallback', 'txHash', txHash);
304
305
  }
305
306
  const response = {
306
307
  success: true,
@@ -308,13 +309,13 @@ async function SendTransactionLedger(config, script) {
308
309
  };
309
310
  /* istanbul ignore if */
310
311
  if (config.Debug) {
311
- console.log('response', response);
312
+ logger_js_1.logger.log('response', response);
312
313
  }
313
314
  return response;
314
315
  }
315
316
  catch (error) {
316
317
  if (config.Debug) {
317
- console.log('error', error);
318
+ logger_js_1.logger.log('error', error);
318
319
  }
319
320
  const errorResponse = {
320
321
  success: false,
@@ -341,24 +342,24 @@ const GetBalanceFromPrivateKey = async (config, privateKey) => {
341
342
  }
342
343
  /* istanbul ignore if */
343
344
  if (config.Debug) {
344
- console.log('privateKey', privateKey);
345
+ logger_js_1.logger.log('privateKey', privateKey);
345
346
  }
346
347
  // https://github.com/phantasma-io/phantasma-ts/blob/7d04aaed839851ae5640f68ab223ca7d92c42016/core/tx/utils.js
347
348
  const publicKey = (0, Transaction_Sign_js_1.GetPublicFromPrivate)(privateKey);
348
349
  /* istanbul ignore if */
349
350
  if (config.Debug) {
350
- console.log('publicKey', publicKey);
351
+ logger_js_1.logger.log('publicKey', publicKey);
351
352
  }
352
353
  const address = (0, Address_Transcode_js_1.GetAddressFromPublicKey)(publicKey);
353
354
  /* istanbul ignore if */
354
355
  if (config.Debug) {
355
- console.log('address', address);
356
+ logger_js_1.logger.log('address', address);
356
357
  }
357
358
  // const path = `/address/${address}`;
358
359
  // const response = await httpRequestUtil.get(config, path);
359
360
  const rpcResponse = await config.RPC.getAccount(address);
360
361
  if (config.Debug) {
361
- console.log('rpcResponse', rpcResponse);
362
+ logger_js_1.logger.log('rpcResponse', rpcResponse);
362
363
  }
363
364
  let response;
364
365
  response.balances = new Map();
@@ -397,7 +398,7 @@ const GetBalanceFromMnemonic = async (config, mnemonic, index) => {
397
398
  }
398
399
  /* istanbul ignore if */
399
400
  if (config.Debug) {
400
- console.log('mnemonic', mnemonic);
401
+ logger_js_1.logger.log('mnemonic', mnemonic);
401
402
  }
402
403
  const privateKey = (0, index_js_1.GetPrivateKeyFromMnemonic)(config, mnemonic, index);
403
404
  return await (0, exports.GetBalanceFromPrivateKey)(config, privateKey);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SignLedger = exports.DecodeSignature = exports.SplitMessageIntoChunks = exports.ChunkString = exports.GetPublicKey = exports.GetBip44PathMessage = exports.GetVersion = exports.GetApplicationName = exports.GetDevice = exports.GetErrorMessage = exports.ErrorDescriptions = exports.Bip44Path = exports.MAX_SIGNED_TX_LEN = void 0;
4
4
  const index_js_1 = require("../utils/index.js");
5
+ const logger_js_1 = require("../utils/logger.js");
5
6
  exports.MAX_SIGNED_TX_LEN = 1024;
6
7
  const Debug = true;
7
8
  exports.Bip44Path = '8000002C' + // 44
@@ -51,12 +52,12 @@ exports.GetErrorMessage = GetErrorMessage;
51
52
  const GetDevice = async (transport) => {
52
53
  /* istanbul ignore if */
53
54
  if (Debug) {
54
- console.log('getDevice', 'transport', transport);
55
+ logger_js_1.logger.log('getDevice', 'transport', transport);
55
56
  }
56
57
  const supported = await transport.isSupported();
57
58
  /* istanbul ignore if */
58
59
  if (Debug) {
59
- console.log('getDevice', 'supported', supported);
60
+ logger_js_1.logger.log('getDevice', 'supported', supported);
60
61
  }
61
62
  if (!supported) {
62
63
  return {
@@ -68,7 +69,7 @@ const GetDevice = async (transport) => {
68
69
  const list = await transport.list();
69
70
  /* istanbul ignore if */
70
71
  if (Debug) {
71
- console.log('getDevice', 'list', list);
72
+ logger_js_1.logger.log('getDevice', 'list', list);
72
73
  }
73
74
  if (list.length == 0) {
74
75
  return {
@@ -80,12 +81,12 @@ const GetDevice = async (transport) => {
80
81
  const path = list[0];
81
82
  /* istanbul ignore if */
82
83
  if (Debug) {
83
- console.log('getDevice', 'path', path);
84
+ logger_js_1.logger.log('getDevice', 'path', path);
84
85
  }
85
86
  const device = await transport.open(path);
86
87
  /* istanbul ignore if */
87
88
  if (Debug) {
88
- console.log('getDevice', 'device', device);
89
+ logger_js_1.logger.log('getDevice', 'device', device);
89
90
  }
90
91
  return {
91
92
  enabled: true,
@@ -111,13 +112,13 @@ const GetApplicationName = async (transport) => {
111
112
  const request = Buffer.from('E004000000', 'hex');
112
113
  /* istanbul ignore if */
113
114
  if (Debug) {
114
- console.log('exchange', 'request', request.toString('hex').toUpperCase());
115
+ logger_js_1.logger.log('exchange', 'request', request.toString('hex').toUpperCase());
115
116
  }
116
117
  const response = await device.device.exchange(request);
117
118
  const responseStr = response.toString('hex').toUpperCase();
118
119
  /* istanbul ignore if */
119
120
  if (Debug) {
120
- console.log('exchange', 'response', responseStr);
121
+ logger_js_1.logger.log('exchange', 'response', responseStr);
121
122
  }
122
123
  let success = false;
123
124
  let message = '';
@@ -140,7 +141,7 @@ const GetApplicationName = async (transport) => {
140
141
  catch (error) {
141
142
  /* istanbul ignore if */
142
143
  if (Debug) {
143
- console.trace('getApplicationName', 'error', error);
144
+ logger_js_1.logger.trace('getApplicationName', 'error', error);
144
145
  }
145
146
  return {
146
147
  success: false,
@@ -175,13 +176,13 @@ const GetVersion = async (transport) => {
175
176
  const request = Buffer.from('E003000000', 'hex');
176
177
  /* istanbul ignore if */
177
178
  if (Debug) {
178
- console.log('exchange', 'request', request.toString('hex').toUpperCase());
179
+ logger_js_1.logger.log('exchange', 'request', request.toString('hex').toUpperCase());
179
180
  }
180
181
  const response = await device.device.exchange(request);
181
182
  const responseStr = response.toString('hex').toUpperCase();
182
183
  /* istanbul ignore if */
183
184
  if (Debug) {
184
- console.log('exchange', 'response', responseStr);
185
+ logger_js_1.logger.log('exchange', 'response', responseStr);
185
186
  }
186
187
  let success = false;
187
188
  let message = '';
@@ -204,7 +205,7 @@ const GetVersion = async (transport) => {
204
205
  catch (error) {
205
206
  /* istanbul ignore if */
206
207
  if (Debug) {
207
- console.trace('getVersion', 'error', error);
208
+ logger_js_1.logger.trace('getVersion', 'error', error);
208
209
  }
209
210
  return {
210
211
  success: false,
@@ -241,11 +242,11 @@ const GetBip44PathMessage = (messagePrefix) => {
241
242
  const payload = Buffer.concat([bip44PathBufferLenBuffer, bip44PathBuffer]);
242
243
  const payloadLen = (0, index_js_1.Int2Buffer)(payload.length);
243
244
  if (Debug) {
244
- console.log('getBip44PathMessage', 'bip44PathBuffer', bip44PathBuffer.toString('hex').toUpperCase());
245
- console.log('getBip44PathMessage', 'bip44PathBufferLen', bip44PathBufferLen);
246
- console.log('getBip44PathMessage', 'bip44PathBufferLenBuffer', bip44PathBufferLenBuffer.toString('hex').toUpperCase());
247
- console.log('getBip44PathMessage', 'payload', payload.toString('hex').toUpperCase());
248
- console.log('getBip44PathMessage', 'payloadLen', payloadLen.toString('hex').toUpperCase());
245
+ logger_js_1.logger.log('getBip44PathMessage', 'bip44PathBuffer', bip44PathBuffer.toString('hex').toUpperCase());
246
+ logger_js_1.logger.log('getBip44PathMessage', 'bip44PathBufferLen', bip44PathBufferLen);
247
+ logger_js_1.logger.log('getBip44PathMessage', 'bip44PathBufferLenBuffer', bip44PathBufferLenBuffer.toString('hex').toUpperCase());
248
+ logger_js_1.logger.log('getBip44PathMessage', 'payload', payload.toString('hex').toUpperCase());
249
+ logger_js_1.logger.log('getBip44PathMessage', 'payloadLen', payloadLen.toString('hex').toUpperCase());
249
250
  }
250
251
  const message = Buffer.concat([messagePrefix, payloadLen, payload]);
251
252
  return message;
@@ -284,13 +285,13 @@ const GetPublicKey = async (transport, options) => {
284
285
  const request = (0, exports.GetBip44PathMessage)(messagePrefix);
285
286
  /* istanbul ignore if */
286
287
  if (Debug) {
287
- console.log('exchange', 'request', request.toString('hex').toUpperCase());
288
+ logger_js_1.logger.log('exchange', 'request', request.toString('hex').toUpperCase());
288
289
  }
289
290
  const response = await device.device.exchange(request);
290
291
  const responseStr = response.toString('hex').toUpperCase();
291
292
  /* istanbul ignore if */
292
293
  if (Debug) {
293
- console.log('exchange', 'response', responseStr);
294
+ logger_js_1.logger.log('exchange', 'response', responseStr);
294
295
  }
295
296
  let success = false;
296
297
  let message = '';
@@ -312,7 +313,7 @@ const GetPublicKey = async (transport, options) => {
312
313
  catch (error) {
313
314
  /* istanbul ignore if */
314
315
  if (Debug) {
315
- console.trace('getPublicKey', 'error', error);
316
+ logger_js_1.logger.trace('getPublicKey', 'error', error);
316
317
  }
317
318
  return {
318
319
  success: false,
@@ -348,7 +349,7 @@ const SplitMessageIntoChunks = (ledgerMessage) => {
348
349
  const messages = [];
349
350
  messages.push((0, exports.GetBip44PathMessage)(Buffer.from('E006' + '00' + '80', 'hex')));
350
351
  if (Debug) {
351
- console.log('splitMessageIntoChunks', 'ledgerMessage.length', ledgerMessage.length);
352
+ logger_js_1.logger.log('splitMessageIntoChunks', 'ledgerMessage.length', ledgerMessage.length);
352
353
  }
353
354
  // MAX 250, as theres 5 header bytes, and max total buffer size is 255.
354
355
  const bufferSize = 250 * 2;
@@ -358,11 +359,11 @@ const SplitMessageIntoChunks = (ledgerMessage) => {
358
359
  const chunk = chunks[chunkIx];
359
360
  const chunkNbr = chunkIx + 1;
360
361
  if (Debug) {
361
- console.log('splitMessageIntoChunks', 'chunk.length', chunk.length);
362
+ logger_js_1.logger.log('splitMessageIntoChunks', 'chunk.length', chunk.length);
362
363
  }
363
364
  const p1 = chunkNbr.toString(16).padStart(2, '0');
364
365
  if (Debug) {
365
- console.log('splitMessageIntoChunks', 'p1', p1);
366
+ logger_js_1.logger.log('splitMessageIntoChunks', 'p1', p1);
366
367
  }
367
368
  let p2;
368
369
  if (chunkNbr == chunks.length) {
@@ -374,20 +375,20 @@ const SplitMessageIntoChunks = (ledgerMessage) => {
374
375
  p2 = '80';
375
376
  }
376
377
  if (Debug) {
377
- console.log('splitMessageIntoChunks', 'p2', p2);
378
+ logger_js_1.logger.log('splitMessageIntoChunks', 'p2', p2);
378
379
  }
379
380
  const chunkLength = chunk.length / 2;
380
381
  const chunkLengthHex = chunkLength.toString(16).padStart(2, '0');
381
382
  if (Debug) {
382
- console.log('splitMessageIntoChunks', 'chunkLengthHex', chunkLengthHex);
383
+ logger_js_1.logger.log('splitMessageIntoChunks', 'chunkLengthHex', chunkLengthHex);
383
384
  }
384
385
  const messageHex = 'E006' + p1 + p2 + chunkLengthHex + chunk;
385
386
  if (Debug) {
386
- console.log('splitMessageIntoChunks', 'messageHex', messageHex);
387
+ logger_js_1.logger.log('splitMessageIntoChunks', 'messageHex', messageHex);
387
388
  }
388
389
  const message = Buffer.from(messageHex, 'hex');
389
390
  if (Debug) {
390
- console.log('splitMessageIntoChunks', 'message', message);
391
+ logger_js_1.logger.log('splitMessageIntoChunks', 'message', message);
391
392
  }
392
393
  messages.push(message);
393
394
  }
@@ -397,12 +398,12 @@ exports.SplitMessageIntoChunks = SplitMessageIntoChunks;
397
398
  const DecodeSignature = (response) => {
398
399
  /* istanbul ignore if */
399
400
  if (Debug) {
400
- console.log('decodeSignature', 'response', response);
401
+ logger_js_1.logger.log('decodeSignature', 'response', response);
401
402
  }
402
403
  const signature = response.substring(0, 128);
403
404
  /* istanbul ignore if */
404
405
  if (Debug) {
405
- console.log('decodeSignature', 'signature', signature);
406
+ logger_js_1.logger.log('decodeSignature', 'signature', signature);
406
407
  }
407
408
  return signature;
408
409
  };
@@ -410,7 +411,7 @@ exports.DecodeSignature = DecodeSignature;
410
411
  const SignLedger = async (transport, transactionHex) => {
411
412
  /* istanbul ignore if */
412
413
  if (Debug) {
413
- console.log('sign', 'transactionHex', transactionHex);
414
+ logger_js_1.logger.log('sign', 'transactionHex', transactionHex);
414
415
  }
415
416
  // transactionHex = '0200000000000000';
416
417
  const transactionByteLength = Math.ceil(transactionHex.length / 2);
@@ -423,12 +424,12 @@ const SignLedger = async (transport, transactionHex) => {
423
424
  const ledgerMessage = transactionHex;
424
425
  const messages = (0, exports.SplitMessageIntoChunks)(ledgerMessage);
425
426
  if (Debug) {
426
- console.log('sign', 'transport', transport);
427
+ logger_js_1.logger.log('sign', 'transport', transport);
427
428
  }
428
429
  const device = await (0, exports.GetDevice)(transport);
429
430
  if (Debug) {
430
- console.log('sign', 'device', device);
431
- console.log('sign', 'messages.length', messages.length);
431
+ logger_js_1.logger.log('sign', 'device', device);
432
+ logger_js_1.logger.log('sign', 'messages.length', messages.length);
432
433
  }
433
434
  if (!device.enabled) {
434
435
  return {
@@ -443,12 +444,12 @@ const SignLedger = async (transport, transactionHex) => {
443
444
  const message = messages[ix];
444
445
  /* istanbul ignore if */
445
446
  if (Debug) {
446
- console.log('exchange', ix, 'of', messages.length, 'message', message.toString('hex').toUpperCase());
447
+ logger_js_1.logger.log('exchange', ix, 'of', messages.length, 'message', message.toString('hex').toUpperCase());
447
448
  }
448
449
  const response = await device.device.exchange(message);
449
450
  const responseStr = response.toString('hex').toUpperCase();
450
451
  if (Debug) {
451
- console.log('exchange', ix, 'of', messages.length, 'response', responseStr);
452
+ logger_js_1.logger.log('exchange', ix, 'of', messages.length, 'response', responseStr);
452
453
  }
453
454
  if (responseStr !== undefined) {
454
455
  if (!responseStr.endsWith('9000')) {
@@ -483,7 +484,7 @@ const SignLedger = async (transport, transactionHex) => {
483
484
  catch (error) {
484
485
  /* istanbul ignore if */
485
486
  if (Debug) {
486
- console.trace('sign', 'error', error);
487
+ logger_js_1.logger.trace('sign', 'error', error);
487
488
  }
488
489
  return {
489
490
  success: false,
@@ -25,15 +25,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.GetPublicFromPrivate = exports.Verify = exports.Sign = exports.GetHash = exports.SignBytes = exports.PublicToPem = exports.PublicToDer = exports.PrivateToDer = void 0;
27
27
  const crypto = __importStar(require("crypto"));
28
+ const logger_js_1 = require("../utils/logger.js");
28
29
  const PUBLIC_KEY_PREFIX = '302A300506032B6570032100';
29
30
  const DEBUG = false;
30
31
  const PrivateToDer = (privateKeyHex) => {
31
32
  if (DEBUG) {
32
- console.log('privateToDer', 'privateKeyHex', privateKeyHex);
33
+ logger_js_1.logger.log('privateToDer', 'privateKeyHex', privateKeyHex);
33
34
  }
34
35
  const derHex = `302e020100300506032b657004220420${privateKeyHex}`;
35
36
  if (DEBUG) {
36
- console.log('privateToDer', 'derHex', derHex);
37
+ logger_js_1.logger.log('privateToDer', 'derHex', derHex);
37
38
  }
38
39
  return Buffer.from(derHex, 'hex');
39
40
  };
@@ -51,12 +52,12 @@ const PublicToPem = (publicKeyHex) => {
51
52
  exports.PublicToPem = PublicToPem;
52
53
  const SignBytes = (hash, privateKey) => {
53
54
  if (DEBUG) {
54
- console.log('signBytes.hash', hash);
55
- console.log('signBytes.privateKey', privateKey);
55
+ logger_js_1.logger.log('signBytes.hash', hash);
56
+ logger_js_1.logger.log('signBytes.privateKey', privateKey);
56
57
  }
57
58
  const privateKeyDer = (0, exports.PrivateToDer)(privateKey.toString('hex'));
58
59
  if (DEBUG) {
59
- console.log('signBytes.privateKeyDer', privateKeyDer);
60
+ logger_js_1.logger.log('signBytes.privateKeyDer', privateKeyDer);
60
61
  }
61
62
  const privateKeyObj = crypto.createPrivateKey({
62
63
  key: privateKeyDer,
@@ -66,7 +67,7 @@ const SignBytes = (hash, privateKey) => {
66
67
  const signature = crypto.sign(undefined, hash, privateKeyObj);
67
68
  const signatureHex = signature.toString('hex');
68
69
  if (DEBUG) {
69
- console.log('signatureHex', signatureHex);
70
+ logger_js_1.logger.log('signatureHex', signatureHex);
70
71
  }
71
72
  return signatureHex;
72
73
  };
@@ -77,32 +78,32 @@ const GetHash = (encodedTx, debug) => {
77
78
  exports.GetHash = GetHash;
78
79
  const Sign = (encodedTx, privateKeyHex) => {
79
80
  if (DEBUG) {
80
- console.log('sign', 'encodedTx', encodedTx);
81
+ logger_js_1.logger.log('sign', 'encodedTx', encodedTx);
81
82
  }
82
83
  const privateKey = Buffer.from(privateKeyHex, 'hex');
83
84
  if (DEBUG) {
84
- console.log('sign', 'privateKey', privateKey.toString('hex'));
85
+ logger_js_1.logger.log('sign', 'privateKey', privateKey.toString('hex'));
85
86
  }
86
87
  const hash = (0, exports.GetHash)(encodedTx);
87
88
  if (DEBUG) {
88
- console.log('sign', 'hash', hash.toString('hex'));
89
+ logger_js_1.logger.log('sign', 'hash', hash.toString('hex'));
89
90
  }
90
91
  const signature = (0, exports.SignBytes)(hash, privateKey);
91
92
  if (DEBUG) {
92
- console.log('sign', 'signature', signature);
93
+ logger_js_1.logger.log('sign', 'signature', signature);
93
94
  }
94
95
  return signature.toLowerCase();
95
96
  };
96
97
  exports.Sign = Sign;
97
98
  const Verify = (encodedTx, signatureHex, publicKeyHex) => {
98
99
  if (DEBUG) {
99
- console.log('verify', 'encodedTx', encodedTx);
100
- console.log('verify', 'signatureHex', signatureHex);
101
- console.log('verify', 'publicKeyHex', publicKeyHex);
100
+ logger_js_1.logger.log('verify', 'encodedTx', encodedTx);
101
+ logger_js_1.logger.log('verify', 'signatureHex', signatureHex);
102
+ logger_js_1.logger.log('verify', 'publicKeyHex', publicKeyHex);
102
103
  }
103
104
  const publicKeyPem = (0, exports.PublicToPem)(publicKeyHex);
104
105
  if (DEBUG) {
105
- console.log('verify', 'publicKeyPem', publicKeyPem);
106
+ logger_js_1.logger.log('verify', 'publicKeyPem', publicKeyPem);
106
107
  }
107
108
  const publicKeyObj = crypto.createPublicKey({
108
109
  key: publicKeyPem,
@@ -112,7 +113,7 @@ const Verify = (encodedTx, signatureHex, publicKeyHex) => {
112
113
  const signature = Buffer.from(signatureHex, 'hex');
113
114
  const hash = (0, exports.GetHash)(encodedTx);
114
115
  if (DEBUG) {
115
- console.log('verify', 'hash', hash.toString('hex'));
116
+ logger_js_1.logger.log('verify', 'hash', hash.toString('hex'));
116
117
  }
117
118
  return crypto.verify(undefined, hash, publicKeyObj, signature);
118
119
  };
@@ -4,6 +4,7 @@ exports.EasyConnect = void 0;
4
4
  const phantasmaLink_js_1 = require("./phantasmaLink.js");
5
5
  const ProofOfWork_js_1 = require("./interfaces/ProofOfWork.js");
6
6
  const easyScript_js_1 = require("./easyScript.js");
7
+ const logger_js_1 = require("../utils/logger.js");
7
8
  class EasyConnect {
8
9
  constructor(_options = null) {
9
10
  this.platform = 'phantasma';
@@ -24,7 +25,7 @@ class EasyConnect {
24
25
  this.providerHint = _options[2];
25
26
  }
26
27
  catch (error) {
27
- console.log(error);
28
+ logger_js_1.logger.log(error);
28
29
  }
29
30
  }
30
31
  this.script = new easyScript_js_1.EasyScript();
@@ -51,7 +52,7 @@ class EasyConnect {
51
52
  }
52
53
  }
53
54
  connect(onSuccess = (data) => { }, onFail = (data) => {
54
- console.log('%cError: ' + data, 'color:red');
55
+ logger_js_1.logger.log('%cError: ' + data, 'color:red');
55
56
  }) {
56
57
  let that = this;
57
58
  this.link.login(function (data) {
@@ -59,12 +60,12 @@ class EasyConnect {
59
60
  if (data) {
60
61
  that.connected = true;
61
62
  onSuccess(data);
62
- console.log('%c[EasyConnect Connected]', 'color:green');
63
- console.log("Wallet Address '" + that.link.account.address + "' connected via " + that.link.wallet);
63
+ logger_js_1.logger.log('%c[EasyConnect Connected]', 'color:green');
64
+ logger_js_1.logger.log("Wallet Address '" + that.link.account.address + "' connected via " + that.link.wallet);
64
65
  }
65
66
  else {
66
67
  onFail();
67
- console.log('EasyConnect could not connect to wallet');
68
+ logger_js_1.logger.log('EasyConnect could not connect to wallet');
68
69
  }
69
70
  }, onFail, this.requiredVersion, this.platform, this.providerHint);
70
71
  }
@@ -73,7 +74,7 @@ class EasyConnect {
73
74
  this.connected = false;
74
75
  }
75
76
  async query(_type = null, _arguments = null, _callback = (data) => {
76
- console.log(data);
77
+ logger_js_1.logger.log(data);
77
78
  }) {
78
79
  if (this.connected == true) {
79
80
  switch (_type) {
@@ -109,11 +110,11 @@ class EasyConnect {
109
110
  }
110
111
  }
111
112
  else {
112
- console.log('%cWallet is not connected', 'color:red');
113
+ logger_js_1.logger.log('%cWallet is not connected', 'color:red');
113
114
  }
114
115
  }
115
116
  async action(_type = null, _arguments = null, onSuccess = (data) => { }, onFail = (data) => {
116
- console.log('%cError: ' + data, 'color:red');
117
+ logger_js_1.logger.log('%cError: ' + data, 'color:red');
117
118
  }) {
118
119
  if (this.connected == true) {
119
120
  switch (_type) {
@@ -134,28 +135,28 @@ class EasyConnect {
134
135
  }
135
136
  }
136
137
  else {
137
- console.log('%cWallet is not connected', 'color:red');
138
+ logger_js_1.logger.log('%cWallet is not connected', 'color:red');
138
139
  }
139
140
  }
140
141
  signTransaction(script, payload = null, onSuccess = (data) => { }, onFail = (data) => {
141
- console.log('%cError: ' + data, 'color:red');
142
+ logger_js_1.logger.log('%cError: ' + data, 'color:red');
142
143
  }) {
143
144
  this.link.signTx(script, payload, onSuccess, onFail);
144
145
  }
145
146
  signData(data, onSuccess = (data) => { }, onFail = (data) => {
146
- console.log('%cError: ' + data, 'color:red');
147
+ logger_js_1.logger.log('%cError: ' + data, 'color:red');
147
148
  }) {
148
149
  this.link.signData(data, onSuccess, onFail);
149
150
  }
150
151
  signCarbonTransaction(txMsg, onSuccess = (data) => { }, onFail = (data) => {
151
- console.log('%cError: ' + data, 'color:red');
152
+ logger_js_1.logger.log('%cError: ' + data, 'color:red');
152
153
  }) {
153
154
  if (this.connected == true) {
154
155
  this.link.signCarbonTxAndBroadcast(txMsg, onSuccess, onFail);
155
156
  }
156
157
  else {
157
158
  const message = 'Wallet is not connected';
158
- console.log('%c' + message, 'color:red');
159
+ logger_js_1.logger.log('%c' + message, 'color:red');
159
160
  onFail(message);
160
161
  }
161
162
  }
@@ -163,7 +164,7 @@ class EasyConnect {
163
164
  this.link.invokeScript(script, _callback);
164
165
  }
165
166
  deployContract(script, payload = null, proofOfWork = ProofOfWork_js_1.ProofOfWork.Minimal, onSuccess = (data) => { }, onFail = (data) => {
166
- console.log('%cError: ' + data, 'color:red');
167
+ logger_js_1.logger.log('%cError: ' + data, 'color:red');
167
168
  }) {
168
169
  this.link.signTx(script, payload, onSuccess, onFail, proofOfWork);
169
170
  }
@@ -5,6 +5,7 @@ const index_js_1 = require("../vm/index.js");
5
5
  const ProofOfWork_js_1 = require("./interfaces/ProofOfWork.js");
6
6
  const CarbonBlob_js_1 = require("../types/Carbon/CarbonBlob.js");
7
7
  const Hex_js_1 = require("../utils/Hex.js");
8
+ const logger_js_1 = require("../utils/logger.js");
8
9
  class PhantasmaLink {
9
10
  //Construct The Link
10
11
  constructor(dappID, logging = true) {
@@ -13,7 +14,7 @@ class PhantasmaLink {
13
14
  //Message Logging
14
15
  this.onMessage = (msg) => {
15
16
  if (this.messageLogging == true) {
16
- console.log(msg);
17
+ logger_js_1.logger.log(msg);
17
18
  }
18
19
  };
19
20
  this.version = 4;
@@ -26,7 +27,7 @@ class PhantasmaLink {
26
27
  }
27
28
  else {
28
29
  this.messageLogging = true;
29
- console.log('%cPhantasmaLink created', 'color:green');
30
+ logger_js_1.logger.log('%cPhantasmaLink created', 'color:green');
30
31
  }
31
32
  this.requestID = 0;
32
33
  //Standard Sets
@@ -414,7 +415,7 @@ class PhantasmaLink {
414
415
  this.socket.onmessage = function (event) {
415
416
  const obj = JSON.parse(event.data);
416
417
  if (that.messageLogging == true) {
417
- console.log('%c' + event.data, 'color:blue');
418
+ logger_js_1.logger.log('%c' + event.data, 'color:blue');
418
419
  }
419
420
  //Checks What To Do Based On Message
420
421
  switch (obj.message) {