@dydxprotocol/v4-client-js 1.2.1 → 1.3.2

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 (123) hide show
  1. package/__native__/__ios__/v4-native-client.js +5690 -5602
  2. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/cosmos/bundle.d.ts +158 -158
  3. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/cosmos/bundle.js +126 -126
  4. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/accountplus.d.ts +35 -0
  5. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/accountplus.js +127 -0
  6. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/genesis.d.ts +16 -0
  7. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/genesis.js +65 -0
  8. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bundle.d.ts +2762 -1461
  9. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bundle.js +290 -249
  10. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order.d.ts +2 -3
  11. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order.js +3 -4
  12. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order_removals.d.ts +5 -0
  13. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order_removals.js +11 -1
  14. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/process_proposer_matches_events.d.ts +6 -0
  15. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/process_proposer_matches_events.js +1 -1
  16. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.d.ts +130 -6
  17. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.js +252 -5
  18. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.rpc.Query.d.ts +9 -2
  19. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.rpc.Query.js +10 -1
  20. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/events/events.d.ts +202 -4
  21. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/events/events.js +329 -6
  22. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/off_chain_updates/off_chain_updates.d.ts +28 -0
  23. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/off_chain_updates/off_chain_updates.js +92 -7
  24. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/shared/removal_reason.d.ts +5 -0
  25. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/shared/removal_reason.js +11 -1
  26. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/socks/messages.d.ts +20 -0
  27. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/socks/messages.js +54 -2
  28. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/lcd.d.ts +2 -0
  29. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/lcd.js +7 -1
  30. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/genesis.d.ts +19 -0
  31. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/genesis.js +64 -0
  32. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.d.ts +27 -0
  33. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.js +90 -0
  34. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.rpc.Query.d.ts +16 -0
  35. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.rpc.Query.js +52 -0
  36. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.d.ts +35 -0
  37. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.js +98 -0
  38. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.rpc.msg.d.ts +12 -0
  39. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.rpc.msg.js +41 -0
  40. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/ratelimit/pending_send_packet.d.ts +24 -0
  41. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/ratelimit/pending_send_packet.js +73 -0
  42. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/ratelimit/query.d.ts +37 -0
  43. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/ratelimit/query.js +65 -2
  44. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/ratelimit/query.lcd.d.ts +2 -1
  45. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/ratelimit/query.lcd.js +7 -1
  46. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/ratelimit/query.rpc.Query.d.ts +5 -1
  47. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/ratelimit/query.rpc.Query.js +10 -1
  48. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/genesis.d.ts +16 -0
  49. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/genesis.js +64 -0
  50. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/params.d.ts +29 -0
  51. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/params.js +80 -0
  52. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.d.ts +55 -0
  53. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.js +162 -0
  54. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.lcd.d.ts +10 -0
  55. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.lcd.js +23 -0
  56. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.rpc.Query.d.ts +23 -0
  57. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.rpc.Query.js +61 -0
  58. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/revshare.d.ts +23 -0
  59. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/revshare.js +64 -0
  60. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/tx.d.ts +69 -0
  61. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/tx.js +178 -0
  62. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/tx.rpc.msg.d.ts +21 -0
  63. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/tx.rpc.msg.js +47 -0
  64. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.query.d.ts +17 -2
  65. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.query.js +3 -1
  66. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.tx.d.ts +2 -0
  67. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.tx.js +3 -1
  68. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/perpetual_position.d.ts +3 -0
  69. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/perpetual_position.js +11 -3
  70. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/query.d.ts +55 -4
  71. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/query.js +87 -5
  72. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/query.lcd.d.ts +3 -2
  73. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/query.lcd.js +9 -3
  74. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/query.rpc.Query.d.ts +8 -4
  75. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/query.rpc.Query.js +11 -2
  76. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/genesis.d.ts +37 -2
  77. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/genesis.js +104 -5
  78. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/params.d.ts +96 -0
  79. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/params.js +196 -0
  80. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.d.ts +134 -1
  81. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.js +395 -1
  82. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.lcd.d.ts +12 -0
  83. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.lcd.js +49 -0
  84. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.rpc.Query.d.ts +19 -1
  85. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.rpc.Query.js +66 -2
  86. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/share.d.ts +31 -0
  87. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/share.js +108 -0
  88. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.d.ts +84 -2
  89. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.js +151 -2
  90. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.rpc.msg.d.ts +7 -1
  91. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.rpc.msg.js +13 -1
  92. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/vault.d.ts +0 -14
  93. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/vault.js +2 -38
  94. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/gogoproto/bundle.js +2 -2
  95. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/google/bundle.d.ts +174 -174
  96. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/google/bundle.js +12 -12
  97. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/helpers.d.ts +4 -4
  98. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/tendermint/bundle.d.ts +365 -365
  99. package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/tendermint/bundle.js +22 -22
  100. package/build/src/clients/composite-client.js +6 -6
  101. package/build/src/clients/lib/cctpProto.d.ts +4 -4
  102. package/build/src/clients/modules/get.d.ts +1 -1
  103. package/build/src/clients/modules/get.js +3 -3
  104. package/build/src/clients/native.d.ts +2 -1
  105. package/build/src/clients/native.js +36 -4
  106. package/build/src/clients/types.d.ts +7 -7
  107. package/build/src/clients/validator-client.js +4 -4
  108. package/build/src/index.d.ts +1 -0
  109. package/build/src/index.js +3 -2
  110. package/build/src/lib/onboarding.d.ts +17 -0
  111. package/build/src/lib/onboarding.js +31 -10
  112. package/build/src/types.d.ts +1 -1
  113. package/build/tsconfig.tsbuildinfo +1 -0
  114. package/package.json +5 -4
  115. package/src/clients/modules/get.ts +2 -2
  116. package/src/clients/native.ts +37 -3
  117. package/src/index.ts +1 -0
  118. package/src/lib/onboarding.ts +38 -11
  119. package/tsconfig.json +0 -1
  120. package/webpack.config.js +1 -0
  121. package/.telescope.json +0 -15
  122. package/src/codegen/helpers.ts +0 -241
  123. package/src/codegen/index.ts +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dydxprotocol/v4-client-js",
3
- "version": "1.2.1",
3
+ "version": "1.3.2",
4
4
  "description": "General client library for the new dYdX system (v4 decentralized)",
5
5
  "main": "build/src/index.js",
6
6
  "scripts": {
@@ -12,7 +12,6 @@
12
12
  "lint": "eslint --ext .ts,.js .",
13
13
  "prepublishOnly": "npm run compile",
14
14
  "start": "node build/src/index.js",
15
- "transpile": "rm -rf src/codegen && telescope transpile --protoDirs ./proto --outPath ./src/codegen --no-includeAminos --includeLCDClients --includeRPCClients",
16
15
  "test": "NODE_ENV=test jest --testPathIgnorePatterns=__tests__/modules/client/*",
17
16
  "test:watch": "npm test -- --watch",
18
17
  "test-integration": "NODE_ENV=test jest",
@@ -37,7 +36,6 @@
37
36
  "@cosmjs/stargate": "^0.32.1",
38
37
  "@cosmjs/tendermint-rpc": "^0.32.1",
39
38
  "@cosmjs/utils": "^0.32.1",
40
- "@dydxprotocol/v4-proto": "5.0.0-dev.0",
41
39
  "@osmonauts/lcd": "^0.6.0",
42
40
  "@scure/bip32": "^1.1.5",
43
41
  "@scure/bip39": "^1.1.1",
@@ -53,7 +51,6 @@
53
51
  },
54
52
  "devDependencies": {
55
53
  "@dydxprotocol/node-service-base-dev": "^0.2.6",
56
- "@osmonauts/telescope": "0.80.0",
57
54
  "@protobufs/cosmos": "^0.0.11",
58
55
  "@protobufs/gogoproto": "^0.0.10",
59
56
  "@types/ffi-napi": "^4.0.4",
@@ -77,7 +74,11 @@
77
74
  "stream-http": "^3.2.0",
78
75
  "ts-loader": "^9.4.2",
79
76
  "ts-proto": "^1.165.1",
77
+ "util": "^0.12.5",
80
78
  "webpack": "^5.77.0",
81
79
  "webpack-cli": "^5.0.1"
80
+ },
81
+ "peerDependencies": {
82
+ "@dydxprotocol/v4-proto": "6.0.1"
82
83
  }
83
84
  }
@@ -491,9 +491,9 @@ export class Get {
491
491
  return GovV1Module.QueryProposalsResponse.decode(data);
492
492
  }
493
493
 
494
- async getWithdrawalAndTransferGatingStatus(): Promise<SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoResponse> {
494
+ async getWithdrawalAndTransferGatingStatus(perpetualId: number): Promise<SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoResponse> {
495
495
  const requestData = Uint8Array.from(
496
- SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoRequest.encode({}).finish(),
496
+ SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoRequest.encode({ perpetualId }).finish(),
497
497
  );
498
498
 
499
499
  const data = await this.sendQuery(
@@ -16,7 +16,7 @@ import Long from 'long';
16
16
  import { BECH32_PREFIX, GAS_MULTIPLIER, NOBLE_BECH32_PREFIX } from '../lib/constants';
17
17
  import { UserError } from '../lib/errors';
18
18
  import { ByteArrayEncoding, encodeJson } from '../lib/helpers';
19
- import { deriveHDKeyFromEthereumSignature } from '../lib/onboarding';
19
+ import { deriveHDKeyFromEthereumSignature, deriveHDKeyFromMnemonic } from '../lib/onboarding';
20
20
  import { NetworkOptimizer } from '../network_optimizer';
21
21
  import { CompositeClient, MarketInfo } from './composite-client';
22
22
  import {
@@ -147,6 +147,12 @@ export async function connectWallet(mnemonic: string): Promise<string> {
147
147
  globalThis.wallet = await LocalWallet.fromMnemonic(mnemonic, BECH32_PREFIX);
148
148
  globalThis.nobleWallet = await LocalWallet.fromMnemonic(mnemonic, NOBLE_BECH32_PREFIX);
149
149
 
150
+ const { privateKey, publicKey } = deriveHDKeyFromMnemonic(mnemonic);
151
+ globalThis.hdKey = {
152
+ privateKey,
153
+ publicKey,
154
+ };
155
+
150
156
  try {
151
157
  await globalThis.nobleClient?.connect(globalThis.nobleWallet);
152
158
  } catch (e) {
@@ -1211,14 +1217,14 @@ export async function getWithdrawalCapacityByDenom(payload: string): Promise<str
1211
1217
  }
1212
1218
  }
1213
1219
 
1214
- export async function getWithdrawalAndTransferGatingStatus(): Promise<string> {
1220
+ export async function getWithdrawalAndTransferGatingStatus(perpetualId: number): Promise<string> {
1215
1221
  try {
1216
1222
  const client = globalThis.client;
1217
1223
  if (client === undefined) {
1218
1224
  throw new UserError('client is not connected. Call connectClient() first');
1219
1225
  }
1220
1226
 
1221
- const response = await client.validatorClient.get.getWithdrawalAndTransferGatingStatus();
1227
+ const response = await client.validatorClient.get.getWithdrawalAndTransferGatingStatus(perpetualId);
1222
1228
  return encodeJson(response);
1223
1229
  } catch (error) {
1224
1230
  return wrappedError(error);
@@ -1306,6 +1312,34 @@ export async function signCompliancePayload(payload: string): Promise<string> {
1306
1312
  }
1307
1313
  }
1308
1314
 
1315
+ export async function signPushNotificationTokenRegistrationPayload(payload: string): Promise<string> {
1316
+ try {
1317
+ const json = JSON.parse(payload);
1318
+ const message = json.message;
1319
+ if (message === undefined) {
1320
+ throw new UserError('message is not set');
1321
+ }
1322
+ if (!globalThis.hdKey?.privateKey || !globalThis.hdKey?.publicKey) {
1323
+ throw new Error('Missing hdKey');
1324
+ }
1325
+
1326
+ const timestampInSeconds = Math.floor(Date.now() / 1000);
1327
+ const messageToSign: string = `${message}:REGISTER_TOKEN"${''}:${timestampInSeconds}`;
1328
+ const messageHash = sha256(Buffer.from(messageToSign));
1329
+
1330
+ const signed = await Secp256k1.createSignature(messageHash, globalThis.hdKey.privateKey);
1331
+ const signedMessage = signed.toFixedLength();
1332
+
1333
+ return encodeJson({
1334
+ signedMessage: Buffer.from(signedMessage).toString('base64'),
1335
+ publicKey: Buffer.from(globalThis.hdKey.publicKey).toString('base64'),
1336
+ timestamp: timestampInSeconds,
1337
+ });
1338
+ } catch (error) {
1339
+ return wrappedError(error);
1340
+ }
1341
+ }
1342
+
1309
1343
  export async function setSelectedGasDenom(gasDenom: string): Promise<string> {
1310
1344
  try {
1311
1345
  const client = globalThis.client;
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  export * from './types';
3
3
 
4
4
  // Utility functions.
5
+ export * as helpers from './lib/helpers';
5
6
  export * as utils from './lib/utils';
6
7
  export * as validation from './lib/validation';
7
8
  export * as onboarding from './lib/onboarding';
@@ -27,19 +27,11 @@ export const exportMnemonicAndPrivateKey = (
27
27
  publicKey: Uint8Array | null;
28
28
  } => {
29
29
  const mnemonic = entropyToMnemonic(entropy, wordlist);
30
- const seed = mnemonicToSeedSync(mnemonic);
31
-
32
- const hdkey = HDKey.fromMasterSeed(seed);
33
- const derivedHdkey = hdkey.derive(path);
34
-
35
- if (!hdkey.privateKey) {
36
- throw new Error('null hd key');
37
- }
38
-
30
+ const { privateKey, publicKey } = deriveHDKeyFromMnemonic(mnemonic, path);
39
31
  return {
40
32
  mnemonic,
41
- privateKey: derivedHdkey.privateKey,
42
- publicKey: derivedHdkey.publicKey,
33
+ privateKey,
34
+ publicKey,
43
35
  };
44
36
  };
45
37
 
@@ -67,3 +59,38 @@ export const deriveHDKeyFromEthereumSignature = (
67
59
  const entropy = keccak256(rsValues);
68
60
  return exportMnemonicAndPrivateKey(entropy);
69
61
  };
62
+
63
+ /**
64
+ * @description Derive priv/pub keys from mnemonic and BIP44 HD path
65
+ *
66
+ * @url https://github.com/confio/cosmos-hd-key-derivation-spec#bip44
67
+ *
68
+ * @param mnemonic used to generate seed
69
+ *
70
+ * @param path BIP44 HD Path. Default is The Cosmos Hub path
71
+ *
72
+ * @throws Error if the hdkey does not exist
73
+ *
74
+ * @returns Priv/pub keys
75
+ */
76
+ export const deriveHDKeyFromMnemonic = (
77
+ mnemonic: string,
78
+ path: string = "m/44'/118'/0'/0/0",
79
+ ): {
80
+ privateKey: Uint8Array | null;
81
+ publicKey: Uint8Array | null;
82
+ } => {
83
+ const seed = mnemonicToSeedSync(mnemonic);
84
+
85
+ const hdkey = HDKey.fromMasterSeed(seed);
86
+ const derivedHdkey = hdkey.derive(path);
87
+
88
+ if (!hdkey.privateKey) {
89
+ throw new Error('null hd key');
90
+ }
91
+
92
+ return {
93
+ privateKey: derivedHdkey.privateKey,
94
+ publicKey: derivedHdkey.publicKey,
95
+ };
96
+ };
package/tsconfig.json CHANGED
@@ -6,7 +6,6 @@
6
6
  "examples",
7
7
  "scripts",
8
8
  "src",
9
- "codegen.js",
10
9
  "node_modules/@dydxprotocol/v4-proto/**/**.ts"
11
10
  ],
12
11
  "compilerOptions": {
package/webpack.config.js CHANGED
@@ -31,6 +31,7 @@ module.exports = {
31
31
  http: require.resolve('stream-http'),
32
32
  path: require.resolve('path-browserify'),
33
33
  crypto: require.resolve('crypto-browserify'),
34
+ util: require.resolve('util'),
34
35
  },
35
36
  },
36
37
  plugins: [
package/.telescope.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "protoDirs": ["./proto"],
3
- "outPath": "./src/codegen",
4
- "options": {
5
- "aminoEncoding": {
6
- "enabled": false
7
- },
8
- "lcdClients": {
9
- "enabled": true
10
- },
11
- "rpcClients": {
12
- "enabled": true
13
- }
14
- }
15
- }
@@ -1,241 +0,0 @@
1
- /**
2
- * This file and any referenced files were automatically generated by @osmonauts/telescope@0.80.0
3
- * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
4
- * and run the transpile command or yarn proto command to regenerate this bundle.
5
- */
6
-
7
- import * as _m0 from 'protobufjs/minimal';
8
- import Long from 'long';
9
-
10
- // @ts-ignore
11
- if (_m0.util.Long !== Long) {
12
- _m0.util.Long = Long as any;
13
-
14
- _m0.configure();
15
- }
16
-
17
- export { Long };
18
-
19
- declare var self: any | undefined;
20
- declare var window: any | undefined;
21
- declare var global: any | undefined;
22
- var globalThis: any = (() => {
23
- if (typeof globalThis !== 'undefined') return globalThis;
24
- if (typeof self !== 'undefined') return self;
25
- if (typeof window !== 'undefined') return window;
26
- if (typeof global !== 'undefined') return global;
27
- throw 'Unable to locate global object';
28
- })();
29
-
30
- const atob: (b64: string) => string =
31
- globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
32
-
33
- export function bytesFromBase64(b64: string): Uint8Array {
34
- const bin = atob(b64);
35
- const arr = new Uint8Array(bin.length);
36
- for (let i = 0; i < bin.length; ++i) {
37
- arr[i] = bin.charCodeAt(i);
38
- }
39
- return arr;
40
- }
41
-
42
- const btoa: (bin: string) => string =
43
- globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
44
-
45
- export function base64FromBytes(arr: Uint8Array): string {
46
- const bin: string[] = [];
47
- arr.forEach((byte) => {
48
- bin.push(String.fromCharCode(byte));
49
- });
50
- return btoa(bin.join(''));
51
- }
52
-
53
- export interface AminoHeight {
54
- readonly revision_number?: string;
55
- readonly revision_height?: string;
56
- }
57
-
58
- export function omitDefault<T extends string | number | Long>(input: T): T | undefined {
59
- if (typeof input === 'string') {
60
- return input === '' ? undefined : input;
61
- }
62
-
63
- if (typeof input === 'number') {
64
- return input === 0 ? undefined : input;
65
- }
66
-
67
- if (Long.isLong(input)) {
68
- return input.isZero() ? undefined : input;
69
- }
70
-
71
- throw new Error(`Got unsupported type ${typeof input}`);
72
- }
73
-
74
- interface Duration {
75
- /**
76
- * Signed seconds of the span of time. Must be from -315,576,000,000
77
- * to +315,576,000,000 inclusive. Note: these bounds are computed from:
78
- * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
79
- */
80
- seconds: Long;
81
- /**
82
- * Signed fractions of a second at nanosecond resolution of the span
83
- * of time. Durations less than one second are represented with a 0
84
- * `seconds` field and a positive or negative `nanos` field. For durations
85
- * of one second or more, a non-zero value for the `nanos` field must be
86
- * of the same sign as the `seconds` field. Must be from -999,999,999
87
- * to +999,999,999 inclusive.
88
- */
89
-
90
- nanos: number;
91
- }
92
-
93
- export function toDuration(duration: string): Duration {
94
- return {
95
- seconds: Long.fromNumber(Math.floor(parseInt(duration) / 1000000000)),
96
- nanos: parseInt(duration) % 1000000000,
97
- };
98
- }
99
-
100
- export function fromDuration(duration: Duration): string {
101
- return (parseInt(duration.seconds.toString()) * 1000000000 + duration.nanos).toString();
102
- }
103
-
104
- export function isSet(value: any): boolean {
105
- return value !== null && value !== undefined;
106
- }
107
-
108
- export function isObject(value: any): boolean {
109
- return typeof value === 'object' && value !== null;
110
- }
111
-
112
- export interface PageRequest {
113
- key: Uint8Array;
114
- offset: Long;
115
- limit: Long;
116
- countTotal: boolean;
117
- reverse: boolean;
118
- }
119
-
120
- export interface PageRequestParams {
121
- 'pagination.key'?: string;
122
- 'pagination.offset'?: string;
123
- 'pagination.limit'?: string;
124
- 'pagination.count_total'?: boolean;
125
- 'pagination.reverse'?: boolean;
126
- }
127
-
128
- export interface Params {
129
- params: PageRequestParams;
130
- }
131
-
132
- export const setPaginationParams = (options: Params, pagination?: PageRequest) => {
133
- if (!pagination) {
134
- return options;
135
- }
136
-
137
- if (typeof pagination?.countTotal !== 'undefined') {
138
- options.params['pagination.count_total'] = pagination.countTotal;
139
- }
140
- if (typeof pagination?.key !== 'undefined') {
141
- // String to Uint8Array
142
- // let uint8arr = new Uint8Array(Buffer.from(data,'base64'));
143
-
144
- // Uint8Array to String
145
- options.params['pagination.key'] = Buffer.from(pagination.key).toString('base64');
146
- }
147
- if (typeof pagination?.limit !== 'undefined') {
148
- options.params['pagination.limit'] = pagination.limit.toString();
149
- }
150
- if (typeof pagination?.offset !== 'undefined') {
151
- options.params['pagination.offset'] = pagination.offset.toString();
152
- }
153
- if (typeof pagination?.reverse !== 'undefined') {
154
- options.params['pagination.reverse'] = pagination.reverse;
155
- }
156
-
157
- return options;
158
- };
159
-
160
- type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
161
-
162
- export type DeepPartial<T> = T extends Builtin
163
- ? T
164
- : T extends Long
165
- ? string | number | Long
166
- : T extends Array<infer U>
167
- ? Array<DeepPartial<U>>
168
- : T extends ReadonlyArray<infer U>
169
- ? ReadonlyArray<DeepPartial<U>>
170
- : T extends {}
171
- ? { [K in keyof T]?: DeepPartial<T[K]> }
172
- : Partial<T>;
173
-
174
- type KeysOfUnion<T> = T extends T ? keyof T : never;
175
- export type Exact<P, I extends P> = P extends Builtin
176
- ? P
177
- : P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
178
-
179
- export interface Rpc {
180
- request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
181
- }
182
-
183
- interface Timestamp {
184
- /**
185
- * Represents seconds of UTC time since Unix epoch
186
- * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
187
- * 9999-12-31T23:59:59Z inclusive.
188
- */
189
- seconds: Long;
190
- /**
191
- * Non-negative fractions of a second at nanosecond resolution. Negative
192
- * second values with fractions must still have non-negative nanos values
193
- * that count forward in time. Must be from 0 to 999,999,999
194
- * inclusive.
195
- */
196
-
197
- nanos: number;
198
- }
199
-
200
- export function toTimestamp(date: Date): Timestamp {
201
- const seconds = numberToLong(date.getTime() / 1_000);
202
- const nanos = (date.getTime() % 1000) * 1000000;
203
- return {
204
- seconds,
205
- nanos,
206
- };
207
- }
208
-
209
- export function fromTimestamp(t: Timestamp): Date {
210
- let millis = t.seconds.toNumber() * 1000;
211
- millis += t.nanos / 1000000;
212
- return new Date(millis);
213
- }
214
-
215
- const fromJSON = (object: any): Timestamp => {
216
- return {
217
- seconds: isSet(object.seconds) ? Long.fromString(object.seconds) : Long.ZERO,
218
- nanos: isSet(object.nanos) ? Number(object.nanos) : 0,
219
- };
220
- };
221
-
222
- const timestampFromJSON = (object: any): Timestamp => {
223
- return {
224
- seconds: isSet(object.seconds) ? Long.fromValue(object.seconds) : Long.ZERO,
225
- nanos: isSet(object.nanos) ? Number(object.nanos) : 0,
226
- };
227
- };
228
-
229
- export function fromJsonTimestamp(o: any): Timestamp {
230
- if (o instanceof Date) {
231
- return toTimestamp(o);
232
- } else if (typeof o === 'string') {
233
- return toTimestamp(new Date(o));
234
- } else {
235
- return timestampFromJSON(o);
236
- }
237
- }
238
-
239
- function numberToLong(number: number) {
240
- return Long.fromNumber(number);
241
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * This file and any referenced files were automatically generated by @osmonauts/telescope@0.80.0
3
- * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
4
- * and run the transpile command or yarn proto command to regenerate this bundle.
5
- */