@witnet/sdk 1.0.0-beta.5 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/package.json +3 -1
  2. package/dist/src/bin/helpers.d.ts +1 -0
  3. package/dist/src/bin/helpers.d.ts.map +1 -1
  4. package/dist/src/bin/helpers.js +11 -1
  5. package/dist/src/lib/crypto/interfaces.d.ts +7 -0
  6. package/dist/src/lib/crypto/interfaces.d.ts.map +1 -1
  7. package/dist/src/lib/crypto/interfaces.js +1 -1
  8. package/dist/src/lib/crypto/payloads.d.ts.map +1 -1
  9. package/dist/src/lib/crypto/payloads.js +1 -12
  10. package/dist/src/lib/crypto/signer.d.ts +8 -1
  11. package/dist/src/lib/crypto/signer.d.ts.map +1 -1
  12. package/dist/src/lib/crypto/signer.js +23 -2
  13. package/dist/src/lib/crypto/types.d.ts +2 -2
  14. package/dist/src/lib/crypto/types.d.ts.map +1 -1
  15. package/dist/src/lib/crypto/types.js +4 -5
  16. package/dist/src/lib/crypto/utils.d.ts +2 -1
  17. package/dist/src/lib/crypto/utils.d.ts.map +1 -1
  18. package/dist/src/lib/crypto/utils.js +6 -1
  19. package/dist/src/lib/crypto/wallet.d.ts.map +1 -1
  20. package/dist/src/lib/crypto/wallet.js +1 -4
  21. package/dist/src/lib/utils.d.ts +3 -2
  22. package/dist/src/lib/utils.d.ts.map +1 -1
  23. package/dist/src/lib/utils.js +16 -9
  24. package/dist/witnet/assets/index.d.ts +6 -6
  25. package/dist/witnet/assets/modals/index.d.ts +10 -11
  26. package/dist/witnet/assets/modals/index.js +2 -12
  27. package/dist/witnet/assets/modals/web3/ipfs.d.ts +5 -0
  28. package/dist/witnet/assets/modals/web3/ipfs.d.ts.map +1 -0
  29. package/dist/witnet/assets/modals/web3/ipfs.js +16 -0
  30. package/dist/witnet/assets/modals/web3/wit.d.ts +1 -1
  31. package/dist/witnet/assets/modals/web3/wit.js +4 -4
  32. package/dist/witnet/assets/requests.js +1 -1
  33. package/package.json +3 -1
  34. package/src/bin/cli/radon.js +3 -3
  35. package/src/bin/cli/wallet.js +124 -30
  36. package/src/bin/helpers.js +12 -1
  37. package/witnet/assets/modals/index.js +1 -17
  38. package/witnet/assets/modals/web3/ipfs.js +19 -0
  39. package/witnet/assets/modals/web3/wit.js +3 -3
  40. package/witnet/assets/requests.js +1 -0
@@ -128,7 +128,7 @@ module.exports = {
128
128
  },
129
129
  },
130
130
  init: {
131
- hint: "Initialize Witnet Radon workspace within your project.",
131
+ hint: "Initialize a Witnet Radon workspace in this project.",
132
132
  },
133
133
  },
134
134
  subcommands: {
@@ -543,7 +543,7 @@ function traceWitnetRadonRequest (request, options) {
543
543
  }`
544
544
  )
545
545
  console.info(`${indent} │ ${sep} > URL query: ${helpers.colors.green(source.url)}`)
546
- if (source?.headers && source?.headers.length > 0) {
546
+ if (source?.headers) {
547
547
  console.info(`${indent} │ ${sep} > HTTP headers: ${helpers.colors.green(JSON.stringify(source.headers))}`)
548
548
  }
549
549
  if (source?.body) {
@@ -677,7 +677,7 @@ async function traceWitnetRadonRequestDryRun (request, options) {
677
677
  }`
678
678
  )
679
679
  console.info(`${indent} │ ${sep} > URL query: ${helpers.colors.green(source.url)}`)
680
- if (source?.headers && source?.headers.length > 0) {
680
+ if (source?.headers) {
681
681
  console.info(`${indent} │ ${sep} > HTTP headers: ${helpers.colors.green(JSON.stringify(source.headers))}`)
682
682
  }
683
683
  if (source?.body) {
@@ -63,6 +63,10 @@ module.exports = {
63
63
  hint: "List wallet's HD-accounts treasuring staked, locked or unlocked Wits.",
64
64
  params: ["[WIT_ADDRESSES ...]"],
65
65
  options: {
66
+ ethereum: {
67
+ hint: "Generate account ownership proofs verifiable in Ethereum networks.",
68
+ param: "EVM_ADDRESS"
69
+ },
66
70
  limit: {
67
71
  hint: "Max number of HD-accounts to derive.",
68
72
  param: "LIMIT",
@@ -97,7 +101,7 @@ module.exports = {
97
101
  },
98
102
  },
99
103
  },
100
- decipher: {
104
+ decipherMasterKey: {
101
105
  hint: "Decipher some master key as exported from myWitWallet.",
102
106
  },
103
107
  delegatees: {
@@ -125,6 +129,30 @@ module.exports = {
125
129
  provider: {
126
130
  hint: "Show the underlying Wit/Oracle RPC provider being used.",
127
131
  },
132
+ signMessage: {
133
+ hint: "Prove ownership of a wallet address by signing some given message.",
134
+ param: "TEXT",
135
+ options: {
136
+ signer: {
137
+ hint: "Wallet's signer address other than wallet's default.",
138
+ param: "WALLET_ADDRESS",
139
+ },
140
+ },
141
+ },
142
+ verifyMessage: {
143
+ hint: "Verify authenticity of some given message and signature.",
144
+ param: "TEXT",
145
+ options: {
146
+ publicKey: {
147
+ hint: "Hexified public key of the alleged signer of the message.",
148
+ param: "<HEX_STRING>",
149
+ },
150
+ signature: {
151
+ hint: "Hexified signature produced with the signer's private key.",
152
+ param: "<HEX_STRING>",
153
+ },
154
+ },
155
+ },
128
156
  stake: {
129
157
  hint: "Stake specified amount of Wits by using some given authorization code.",
130
158
  params: "AUTH_CODE",
@@ -195,15 +223,70 @@ module.exports = {
195
223
  },
196
224
  },
197
225
  subcommands: {
198
- accounts, coinbase, decipher, delegatees: validators, notarize: resolve, provider, stake, transfer, withdraw: unstake, utxos,
226
+ accounts, coinbase, delegatees: validators,
227
+ notarize: resolve, stake, transfer, withdraw: unstake, utxos,
228
+ decipherMasterKey: decipher, provider,
229
+ signMessage, verifyMessage,
199
230
  },
200
231
  }
201
232
 
202
233
  /// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
203
234
  /// CLI SUBMODULE COMMANDS ============================================================================================
204
235
 
236
+ async function signMessage (options = {}, [...words]) {
237
+ const wallet = await _loadWallet({
238
+ ...options,
239
+ limit: 1,
240
+ "no-funds": true,
241
+ })
242
+ if (!words.length) {
243
+ throw Error(`some message must be entered.`)
244
+ }
245
+ const text = words.join(" ")
246
+ let ledger
247
+ if (options?.signer) {
248
+ ledger = options.signer === wallet.coinbase.pkh ? wallet.coinbase : wallet.getAccount(options.signer)
249
+ } else {
250
+ ledger = wallet
251
+ }
252
+ if (!ledger) {
253
+ throw Error(`no private key available for signer address ${options?.signer}`)
254
+ }
255
+ console.info(ledger.getSigner().signMessage(text))
256
+ }
257
+
258
+ async function verifyMessage (options = {}, [...words]) {
259
+ if (!words.length) {
260
+ throw Error(`some text must be entered.`)
261
+ }
262
+ const text = words.join(" ")
263
+ const digest = utils.digestMessage(text)
264
+ let { publicKey, signature } = options
265
+ if (!publicKey) {
266
+ throw Error(`--publicKey must be specified.`)
267
+ } else if (!signature) {
268
+ throw Error(`--signature must be specified`)
269
+ }
270
+ if (publicKey.startsWith("0x")) publicKey = publicKey.slice(2);
271
+ if (signature.startsWith("0x")) signature = signature.slice(2);
272
+ console.info(`Message: "${text}"`)
273
+ console.info(`Digest: ${utils.toHexString(digest)}`)
274
+ console.info(`Public key: ${publicKey}`)
275
+ console.info(`Signature: ${signature}`)
276
+ console.info("-".repeat(120))
277
+ if (utils.ecdsaVerify(digest, publicKey, signature.slice(2))) {
278
+ console.info(
279
+ `^ Signed by ${
280
+ Witnet.PublicKey.fromUint8Array(utils.fromHexString(publicKey)).hash().toBech32("mainnet")
281
+ }.\n^ Message is authentic.`
282
+ );
283
+ } else {
284
+ console.error(`^ Invalid signature.`)
285
+ }
286
+ }
287
+
205
288
  async function accounts (options = {}, args = []) {
206
- const { verbose } = options
289
+ const { ethereum, verbose } = options
207
290
 
208
291
  let wallet
209
292
  if (args.length === 0) {
@@ -256,6 +339,9 @@ async function accounts (options = {}, args = []) {
256
339
  balance.unlocked > 0 ? colors.mmagenta(account.pkh) : colors.magenta(account.pkh),
257
340
  utxos.length,
258
341
  balance,
342
+ ...(ethereum ? [
343
+ account.getSigner().authorizeEvmAddress(ethereum),
344
+ ] : [])
259
345
  ]
260
346
  }),
261
347
  )
@@ -263,45 +349,53 @@ async function accounts (options = {}, args = []) {
263
349
 
264
350
  let unlocked = 0n
265
351
  helpers.traceTable(
266
- records.map(([index, pkh, count, balance]) => {
352
+ records.map(([index, pkh, count, balance, signature]) => {
267
353
  unlocked += balance.unlocked
268
354
  return [
269
- index,
270
- pkh,
271
- count,
272
- ...(verbose
273
- ? [
274
- Witnet.Coins.fromNanowits(balance.locked).wits.toFixed(2),
275
- Witnet.Coins.fromNanowits(balance.staked).wits.toFixed(2),
276
- Witnet.Coins.fromNanowits(balance.unlocked).wits.toFixed(2),
277
- utils.totalCoins(balance).wits.toFixed(2),
278
- ]
279
- : [
280
- Witnet.Coins.fromNanowits(balance.unlocked).wits.toFixed(2),
281
- ]
355
+ index, pkh,
356
+ ...(ethereum ? [ signature ] : (
357
+ verbose
358
+ ? [
359
+ count,
360
+ Witnet.Coins.fromNanowits(balance.locked).wits.toFixed(2),
361
+ Witnet.Coins.fromNanowits(balance.staked).wits.toFixed(2),
362
+ Witnet.Coins.fromNanowits(balance.unlocked).wits.toFixed(2),
363
+ utils.totalCoins(balance).wits.toFixed(2),
364
+ ]
365
+ : [
366
+ count,
367
+ Witnet.Coins.fromNanowits(balance.unlocked).wits.toFixed(2),
368
+ ]
369
+ )
282
370
  ),
283
371
  ]
284
372
  }), {
285
373
  headlines: [
286
- "INDEX", `:WALLET ${wallet.network.toUpperCase()} ACCOUNTS`,
287
- "# UTXOs",
288
- ...(verbose
289
- ? ["Locked ($WIT)", "Staked ($WIT)", "Available ($WIT)", "BALANCE ($WIT)"]
290
- : ["Available ($WIT)"]
291
- ),
374
+ "INDEX", `:WITNET WALLET ${wallet.network.toUpperCase()} ACCOUNTS`,
375
+ ...(ethereum ? [`ETHEREUM ${wallet.network.toUpperCase()} WRAPPING AUTHORIZATION CODE [${ethereum}]`] : (
376
+ verbose
377
+ ? ["# UTXOS", "Locked ($WIT)", "Staked ($WIT)", "Available ($WIT)", "BALANCE ($WIT)"]
378
+ : ["# UTXOS", "Available ($WIT)"]
379
+ )
380
+ )
292
381
  ],
293
382
  humanizers: [
294
383
  helpers.commas,,
295
- helpers.commas, helpers.commas, helpers.commas, helpers.commas, helpers.commas,
384
+ ...(ethereum
385
+ ? [,]
386
+ : [helpers.commas, helpers.commas, helpers.commas, helpers.commas, helpers.commas]
387
+ ),
296
388
  ],
297
389
  colors: [
298
390
  ,,
299
- ...(verbose
300
- ? [colors.white, colors.gray, colors.yellow, colors.myellow, colors.lyellow]
301
- : [colors.white, colors.myellow]
391
+ ...(ethereum ? [colors.mblue, colors.gray] : (
392
+ verbose
393
+ ? [colors.white, colors.gray, colors.yellow, colors.myellow, colors.lyellow]
394
+ : [colors.white, colors.myellow]
395
+ )
302
396
  ),
303
397
  ],
304
- maxColumnWidth: 48,
398
+ maxColumnWidth: 132,
305
399
  }
306
400
  )
307
401
  console.info(`^ Available balance: ${colors.lyellow(whole_wits(unlocked, 2))}`)
@@ -705,7 +799,7 @@ async function utxos (options = {}) {
705
799
  utxo?.internal ? colors.green(utxo.output_pointer) : colors.mgreen(utxo.output_pointer),
706
800
  utxo.value,
707
801
  ]), {
708
- headlines: ["INDEX", `WALLET ${wallet.network.toUpperCase()} ADDRESSES`, ":Unlocked UTXO pointers", "UTXO value ($pedros)"],
802
+ headlines: ["INDEX", `WITNET WALLET ${wallet.network.toUpperCase()} ADDRESSES`, ":Unlocked UTXO pointers", "UTXO value ($pedros)"],
709
803
  humanizers: [helpers.commas,,, helpers.commas],
710
804
  colors: [,,, colors.myellow],
711
805
  }
@@ -780,7 +874,7 @@ async function validators (options = {}) {
780
874
  }), {
781
875
  headlines: [
782
876
  // "INDEX",
783
- coinbase ? "WALLET COINBASE" : `WALLET ${wallet.network.toUpperCase()} ACCOUNTS`,
877
+ coinbase ? "WITNET WALLET COINBASE" : `WITNET WALLET ${wallet.network.toUpperCase()} ACCOUNTS`,
784
878
  "STAKE DELEGATEES",
785
879
  ...(verbose
786
880
  ? ["Nonce", "LW_Epoch", "LM_Epoch"]
@@ -433,6 +433,16 @@ function toUpperCamelCase (str) {
433
433
  }).replace(/\s+/g, "")
434
434
  }
435
435
 
436
+ function toUtf16Bytes(str) {
437
+ const bytes = new Uint8Array(str.length * 2);
438
+ for (let i = 0; i < str.length; i++) {
439
+ const code = str.charCodeAt(i);
440
+ bytes[i * 2] = code >> 8;
441
+ bytes[i * 2 + 1] = code & 0xff;
442
+ }
443
+ return bytes;
444
+ }
445
+
436
446
  function toUtf8Array (str) {
437
447
  const utf8 = []
438
448
  for (let i = 0; i < str.length; i++) {
@@ -809,7 +819,8 @@ module.exports = {
809
819
  showVersion,
810
820
  toolkitRun,
811
821
  toUpperCamelCase,
812
- toUtf8Array,
822
+ toUtf16Bytes,
823
+ toUtf8Array,
813
824
  utf8ArrayToStr,
814
825
  prompt,
815
826
  prompter,
@@ -1,25 +1,9 @@
1
- const {
2
- RadonModal,
3
- RadonScript,
4
- retrievals,
5
- types,
6
- } = require("../../../src/lib/radon")
7
-
8
1
  module.exports = {
9
- web: {
10
- WitOracleWebFileExists: new RadonModal({
11
- retrieval: retrievals.HttpHead({
12
- headers: {},
13
- script: RadonScript(types.RadonString),
14
- }),
15
- }),
16
- WitOracleWebFileSha256: {},
17
- WitOracleWebFileSha256Sealed: {},
18
- },
19
2
  web3: {
20
3
  // btc: require("./web3/btc"),
21
4
  eth: require("./web3/eth.js"),
22
5
  // sol: require("./web3/sol"),
6
+ ipfs: require("./web3/ipfs.js"),
23
7
  wit: require("./web3/wit.js"),
24
8
  },
25
9
  }
@@ -0,0 +1,19 @@
1
+ const {
2
+ RadonModal,
3
+ RadonScript,
4
+ // filters,
5
+ // reducers,
6
+ retrievals,
7
+ types,
8
+ } = require("../../../../src/lib/radon")
9
+
10
+ module.exports = {
11
+ WitOracleIpfsFileExists: new RadonModal({
12
+ retrieval: retrievals.HttpHead({
13
+ headers: {},
14
+ script: RadonScript(types.RadonString),
15
+ }),
16
+ }),
17
+ WitOracleIpfsFileSha256: {},
18
+ WitOracleIpfsFileSha256Sealed: {},
19
+ }
@@ -11,13 +11,13 @@ module.exports = {
11
11
  WitOracleWitGetBalance: new RadonModal({
12
12
  retrieval: retrievals.JsonRPC({
13
13
  rpc: retrievals.rpc.wit.getBalance("\\1\\"),
14
- script: RadonScript(types.RadonString).asFloat().floor(),
14
+ script: RadonScript(types.RadonString).parseJSONMap().getMap("result").values(),
15
15
  }),
16
16
  }),
17
- WitOracleWitGetTransaction: new RadonModal({
17
+ WitOracleWitGetValueTransfer: new RadonModal({
18
18
  retrieval: retrievals.JsonRPC({
19
19
  rpc: retrievals.rpc.wit.getTransaction("\\1\\"),
20
- script: RadonScript(types.RadonString).parseJSONMap().getMap("result"),
20
+ script: RadonScript(types.RadonString).parseJSONMap().getMap("result").getMap("Simple").values(),
21
21
  }),
22
22
  }),
23
23
  }
@@ -8,6 +8,7 @@ const {
8
8
  } = require("../../src/lib/radon")
9
9
 
10
10
  module.exports = {
11
+
11
12
  defi: {
12
13
  tickers: {
13
14
  crypto: {