@onekeyfe/onekey-near-provider 0.0.4 → 0.0.5

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,18 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  import { ProviderNearBase } from './ProviderNearBase';
3
3
  import { IJsonRpcRequest } from '@onekeyfe/cross-inpage-provider-types';
4
- import { Account } from 'near-api-js';
5
- import type { Action as NearTransactionAction } from 'near-api-js/lib/transaction';
4
+ import { Account, Connection, transactions } from 'near-api-js';
5
+ import type { Action as NearTransactionAction, Transaction as NearTransaction } from 'near-api-js/lib/transaction';
6
+ import type { AccessKeyInfoView, FinalExecutionOutcome } from 'near-api-js/lib/providers/provider';
6
7
  import { IInpageProviderConfig } from '@onekeyfe/cross-inpage-provider-core';
7
8
  export declare type NearAccountInfo = {
8
9
  accountId: string;
9
10
  publicKey: string;
10
11
  allKeys?: string[];
11
12
  };
12
- export declare type NearNetworkChangedPayload = {
13
+ export declare type NearNetworkInfo = {
13
14
  networkId: string;
14
15
  nodeUrls?: string[];
15
16
  };
17
+ export declare type NearNetworkChangedPayload = NearNetworkInfo;
16
18
  export declare type NearProviderState = {
17
19
  accounts: Array<NearAccountInfo>;
18
20
  network: NearNetworkChangedPayload;
@@ -23,20 +25,7 @@ export declare type NearAccountsChangedPayload = {
23
25
  export declare type NearUnlockChangedPayload = {
24
26
  isUnlocked: boolean;
25
27
  };
26
- export declare type NearBlockInfoHeader = {
27
- hash: string;
28
- };
29
- export declare type NearBlockInfo = {
30
- header: NearBlockInfoHeader;
31
- };
32
- export declare type NearConnectionProvider = {
33
- sendJsonRpc: (method: string, params: object) => Promise<any>;
34
- block: (params: object) => Promise<NearBlockInfo>;
35
- query: (...args: any) => Promise<any>;
36
- };
37
- export declare type NearConnection = {
38
- provider: NearConnectionProvider;
39
- };
28
+ export declare type NearConnection = Connection;
40
29
  export declare type TransactionCreatorParams = {
41
30
  accountId: string;
42
31
  publicKey: string;
@@ -47,8 +36,8 @@ export declare type TransactionCreatorParams = {
47
36
  };
48
37
  export declare type TransactionCreator = (params: TransactionCreatorParams) => any;
49
38
  export declare type OneKeyNearWalletProps = {
50
- connection: NearConnection | any;
51
- networkId: string;
39
+ connection?: NearConnection | any;
40
+ networkId?: string;
52
41
  connectEagerly?: boolean;
53
42
  enablePageReload?: boolean;
54
43
  timeout?: number;
@@ -60,31 +49,29 @@ export declare type OneKeyWalletAccountProps = {
60
49
  connection: unknown;
61
50
  accountId: string;
62
51
  };
52
+ export declare type CommonOptionsMeta = unknown | string | object;
63
53
  export declare type SignInOptions = {
64
54
  contractId?: string;
65
55
  methodNames?: string[];
66
56
  successUrl?: string;
67
57
  failureUrl?: string;
68
58
  };
69
- export declare type NearTransaction = {
70
- encode: () => Uint8Array;
71
- };
72
- export declare type NearAccountAccessKey = {
73
- nonce: number;
74
- };
75
- export declare type NearAccountAccessKeyInfo = {
76
- public_key: string;
77
- access_key: NearAccountAccessKey;
78
- };
59
+ export declare type SignInResult = NearAccountsChangedPayload;
79
60
  export declare type SignTransactionsOptions = {
80
61
  transactions: NearTransaction[];
81
62
  callbackUrl?: string;
82
- meta?: unknown | string;
63
+ meta?: CommonOptionsMeta;
83
64
  send?: boolean;
84
65
  };
66
+ export declare type SignTransactionsResult = {
67
+ transactionHashes: string[];
68
+ };
85
69
  export declare type SignMessagesOptions = {
86
70
  messages: string[];
87
- meta?: unknown | string | object;
71
+ meta?: CommonOptionsMeta;
72
+ };
73
+ export declare type SignMessagesResult = {
74
+ signatures: string[];
88
75
  };
89
76
  export declare type CreateTransactionOptions = {
90
77
  receiverId: string;
@@ -94,7 +81,7 @@ export declare type CreateTransactionOptions = {
94
81
  export declare type SignAndSendTransactionOptions = {
95
82
  receiverId: string;
96
83
  actions: NearTransactionAction[];
97
- meta?: object;
84
+ meta?: CommonOptionsMeta;
98
85
  callbackUrl?: string;
99
86
  };
100
87
  declare function serializeTransaction({ transaction }: {
@@ -166,15 +153,14 @@ declare class OneKeyNearProvider extends ProviderNearBase {
166
153
  getAccountId(): string;
167
154
  getPublicKey(): string;
168
155
  getAccountInfo(): NearAccountInfo;
169
- getNetworkId(): string;
170
- getSelectedNetwork(): NearNetworkChangedPayload;
156
+ getNetworkInfo(): NearNetworkInfo;
171
157
  _saveAuthData(data: NearAccountInfo): void;
172
- requestSignIn(signInOptions?: SignInOptions): Promise<NearAccountsChangedPayload>;
173
- requestSignTransactions(signTransactionsOptions: SignTransactionsOptions): Promise<unknown>;
174
- requestSignMessages({ messages, meta }: SignMessagesOptions): Promise<unknown>;
158
+ requestSignIn(signInOptions?: SignInOptions): Promise<SignInResult>;
159
+ requestSignTransactions(signTransactionsOptions: SignTransactionsOptions): Promise<SignTransactionsResult>;
160
+ requestSignMessages({ messages, meta, }: SignMessagesOptions): Promise<SignMessagesResult>;
175
161
  request({ method, params }?: IJsonRpcRequest): Promise<unknown>;
176
- sendJsonRpc(method: string, params: object): Promise<any>;
177
- createTransaction({ receiverId, actions, nonceOffset }: CreateTransactionOptions): Promise<NearTransaction>;
162
+ sendJsonRpc(method: string, params: object): Promise<unknown>;
163
+ createTransaction({ receiverId, actions, nonceOffset }: CreateTransactionOptions): Promise<transactions.Transaction>;
178
164
  _clearAuthData(): void;
179
165
  signOut(): void;
180
166
  account(): OneKeyWalletAccount;
@@ -182,7 +168,8 @@ declare class OneKeyNearProvider extends ProviderNearBase {
182
168
  declare class OneKeyWalletAccount extends Account {
183
169
  _wallet: OneKeyNearProvider;
184
170
  constructor({ wallet, connection, accountId }: OneKeyWalletAccountProps);
185
- signAndSendTransaction(signAndSendTransactionOptions: SignAndSendTransactionOptions): Promise<unknown>;
171
+ signAndSendTransaction(signAndSendTransactionOptions: SignAndSendTransactionOptions): Promise<FinalExecutionOutcome>;
172
+ getAccessKeys(): Promise<AccessKeyInfoView[]>;
186
173
  _fetchAccountAccessKey({ publicKey, accountId }: {
187
174
  publicKey: string;
188
175
  accountId: string;
@@ -191,6 +178,6 @@ declare class OneKeyWalletAccount extends Account {
191
178
  publicKey: string;
192
179
  accountId: string;
193
180
  }>;
194
- createTransaction({ receiverId, actions, nonceOffset }: CreateTransactionOptions): Promise<NearTransaction>;
181
+ createTransaction({ receiverId, actions, nonceOffset, }: CreateTransactionOptions): Promise<NearTransaction>;
195
182
  }
196
183
  export { OneKeyNearProvider, OneKeyWalletAccount, serializeTransaction };
@@ -11,7 +11,7 @@ import depd from 'depd';
11
11
  import { ProviderNearBase } from './ProviderNearBase';
12
12
  import entries from 'lodash/entries';
13
13
  import isString from 'lodash/isString';
14
- import { baseDecode } from 'borsh';
14
+ import { baseEncode, baseDecode } from 'borsh';
15
15
  import { Account, utils, transactions } from 'near-api-js';
16
16
  import { getOrCreateExtInjectedJsBridge } from '@onekeyfe/extension-bridge-injected';
17
17
  import { web3Errors } from '@onekeyfe/cross-inpage-provider-errors';
@@ -33,14 +33,16 @@ const DEFAULT_NETWORK_INFO = {
33
33
  };
34
34
  const PROVIDER_METHODS = {
35
35
  near_accounts: 'near_accounts',
36
+ near_network: 'near_network',
36
37
  near_networkInfo: 'near_networkInfo',
38
+ near_requestAccounts: 'near_requestAccounts',
37
39
  near_requestSignIn: 'near_requestSignIn',
38
40
  near_signOut: 'near_signOut',
39
41
  near_requestSignTransactions: 'near_requestSignTransactions',
40
42
  near_sendTransactions: 'near_sendTransactions',
41
43
  near_signTransactions: 'near_signTransactions',
42
- near_requestSignMessages: 'near_requestSignMessages',
43
44
  near_signMessages: 'near_signMessages',
45
+ near_requestSignMessages: 'near_requestSignMessages',
44
46
  };
45
47
  const PROVIDER_EVENTS = {
46
48
  accountsChanged: 'accountsChanged',
@@ -84,13 +86,13 @@ class OneKeyNearProvider extends ProviderNearBase {
84
86
  this._isUnlocked = false;
85
87
  this._initializedEmitted = false;
86
88
  if (!networkId) {
87
- throw new Error('OneKeyNearWallet init error: networkId required.');
89
+ // throw new Error('OneKeyNearWallet init error: networkId required.');
88
90
  }
89
91
  this._authDataKey = keyPrefix + this._authDataKey;
90
92
  this._enablePageReload = enablePageReload;
91
93
  this._connectEagerly = connectEagerly;
92
94
  this._connection = connection;
93
- this._networkId = networkId;
95
+ this._networkId = networkId || '';
94
96
  this._transactionCreator = transactionCreator || defaultTransactionCreator;
95
97
  this._initAuthDataFromStorage();
96
98
  this._registerEvents();
@@ -276,8 +278,8 @@ class OneKeyNearProvider extends ProviderNearBase {
276
278
  return this.bridgeRequest(Object.assign(Object.assign({}, payload), { requestInfo: {
277
279
  accountId: this.getAccountId(),
278
280
  publicKey: this.getPublicKey(),
279
- networkId: this.getNetworkId(),
280
- selectedNetworkId: ((_a = this.getSelectedNetwork()) === null || _a === void 0 ? void 0 : _a.networkId) || '',
281
+ networkId: this._networkId,
282
+ selectedNetworkId: ((_a = this.getNetworkInfo()) === null || _a === void 0 ? void 0 : _a.networkId) || '',
281
283
  } }));
282
284
  }
283
285
  isInstalled() {
@@ -300,10 +302,7 @@ class OneKeyNearProvider extends ProviderNearBase {
300
302
  getAccountInfo() {
301
303
  return this._authData || DEFAULT_AUTH_DATA;
302
304
  }
303
- getNetworkId() {
304
- return this._networkId || '';
305
- }
306
- getSelectedNetwork() {
305
+ getNetworkInfo() {
307
306
  return this._selectedNetwork;
308
307
  }
309
308
  _saveAuthData(data) {
@@ -394,7 +393,7 @@ class OneKeyNearProvider extends ProviderNearBase {
394
393
  return res;
395
394
  });
396
395
  }
397
- requestSignMessages({ messages = [], meta = {} }) {
396
+ requestSignMessages({ messages = [], meta = {}, }) {
398
397
  return __awaiter(this, void 0, void 0, function* () {
399
398
  const res = yield this._callBridgeRequest({
400
399
  method: PROVIDER_METHODS.near_requestSignMessages,
@@ -408,7 +407,11 @@ class OneKeyNearProvider extends ProviderNearBase {
408
407
  return __awaiter(this, void 0, void 0, function* () {
409
408
  const paramsArr = [].concat(params);
410
409
  const paramObj = paramsArr[0];
411
- if (method === PROVIDER_METHODS.near_requestSignIn) {
410
+ if (method === PROVIDER_METHODS.near_network) {
411
+ method = PROVIDER_METHODS.near_networkInfo;
412
+ }
413
+ if (method === PROVIDER_METHODS.near_requestAccounts ||
414
+ method === PROVIDER_METHODS.near_requestSignIn) {
412
415
  return this.requestSignIn(paramObj);
413
416
  }
414
417
  if (method === PROVIDER_METHODS.near_sendTransactions ||
@@ -424,6 +427,9 @@ class OneKeyNearProvider extends ProviderNearBase {
424
427
  method === PROVIDER_METHODS.near_requestSignMessages) {
425
428
  return this.requestSignMessages(paramObj);
426
429
  }
430
+ if (method === PROVIDER_METHODS.near_signOut) {
431
+ return this.signOut();
432
+ }
427
433
  return yield this._callBridgeRequest({
428
434
  method,
429
435
  params,
@@ -435,7 +441,6 @@ class OneKeyNearProvider extends ProviderNearBase {
435
441
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
436
442
  return provider.sendJsonRpc(method, params);
437
443
  }
438
- // SpecialWallet required
439
444
  createTransaction({ receiverId, actions, nonceOffset = 1 }) {
440
445
  return this.account().createTransaction({
441
446
  receiverId,
@@ -477,6 +482,7 @@ class OneKeyWalletAccount extends Account {
477
482
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
478
483
  // @ts-ignore
479
484
  signAndSendTransaction(signAndSendTransactionOptions) {
485
+ var _a;
480
486
  return __awaiter(this, arguments, void 0, function* () {
481
487
  let options = signAndSendTransactionOptions;
482
488
  // eslint-disable-next-line prefer-rest-params
@@ -494,12 +500,44 @@ class OneKeyWalletAccount extends Account {
494
500
  });
495
501
  const txHashList = yield this._wallet.requestSignTransactions({
496
502
  transactions: [transaction],
497
- meta: Object.assign({}, meta),
503
+ meta,
498
504
  callbackUrl,
499
505
  });
500
- // TODO return typeof this.connection.provider.sendTransaction
501
- // same type to pending tx polling result
502
- return txHashList;
506
+ const txHash = (_a = txHashList === null || txHashList === void 0 ? void 0 : txHashList.transactionHashes) === null || _a === void 0 ? void 0 : _a[0];
507
+ if (txHash) {
508
+ // near-api-js/lib/providers/json-rpc-provider.js
509
+ // async txStatus(txHash, accountId)
510
+ const txHashStr = typeof txHash === 'string' ? txHash : baseEncode(txHash);
511
+ const res = (yield this._wallet.request({
512
+ method: 'tx',
513
+ params: [txHashStr, this.accountId],
514
+ }));
515
+ return res;
516
+ }
517
+ throw web3Errors.rpc.internal({
518
+ message: 'Transaction sign and send failed: transactionHash not found',
519
+ });
520
+ });
521
+ }
522
+ getAccessKeys() {
523
+ return __awaiter(this, void 0, void 0, function* () {
524
+ // near-api-js/lib/account.js
525
+ // async getAccessKeys() { ... }
526
+ const response = yield this._wallet.request({
527
+ method: 'query',
528
+ params: {
529
+ request_type: 'view_access_key_list',
530
+ account_id: this.accountId,
531
+ finality: 'optimistic',
532
+ },
533
+ });
534
+ // A breaking API change introduced extra information into the
535
+ // response, so it now returns an object with a `keys` field instead
536
+ // of an array: https://github.com/nearprotocol/nearcore/pull/1789
537
+ if (Array.isArray(response)) {
538
+ return response;
539
+ }
540
+ return response.keys;
503
541
  });
504
542
  }
505
543
  _fetchAccountAccessKey({ publicKey, accountId }) {
@@ -517,7 +555,7 @@ class OneKeyWalletAccount extends Account {
517
555
  throw new Error(`near account access key not found for: ${accountId}`);
518
556
  });
519
557
  }
520
- createTransaction({ receiverId, actions, nonceOffset = 1 }) {
558
+ createTransaction({ receiverId, actions, nonceOffset = 1, }) {
521
559
  return __awaiter(this, void 0, void 0, function* () {
522
560
  const _authData = this._wallet._authData;
523
561
  const publicKey = _authData.publicKey;
@@ -531,7 +569,12 @@ class OneKeyWalletAccount extends Account {
531
569
  publicKey,
532
570
  });
533
571
  const nonce = accessKeyInfo.accessKey.nonce + nonceOffset;
534
- const block = yield this.connection.provider.block({ finality: 'final' });
572
+ // near-api-js/lib/providers/json-rpc-provider.js
573
+ // async block(blockQuery) {...}
574
+ const block = (yield this._wallet.request({
575
+ method: 'block',
576
+ params: { block_id: undefined, finality: 'final' },
577
+ }));
535
578
  const blockHash = baseDecode(block.header.hash);
536
579
  const transaction = this._wallet._transactionCreator({
537
580
  accountId,
@@ -40,14 +40,16 @@ const DEFAULT_NETWORK_INFO = {
40
40
  };
41
41
  const PROVIDER_METHODS = {
42
42
  near_accounts: 'near_accounts',
43
+ near_network: 'near_network',
43
44
  near_networkInfo: 'near_networkInfo',
45
+ near_requestAccounts: 'near_requestAccounts',
44
46
  near_requestSignIn: 'near_requestSignIn',
45
47
  near_signOut: 'near_signOut',
46
48
  near_requestSignTransactions: 'near_requestSignTransactions',
47
49
  near_sendTransactions: 'near_sendTransactions',
48
50
  near_signTransactions: 'near_signTransactions',
49
- near_requestSignMessages: 'near_requestSignMessages',
50
51
  near_signMessages: 'near_signMessages',
52
+ near_requestSignMessages: 'near_requestSignMessages',
51
53
  };
52
54
  const PROVIDER_EVENTS = {
53
55
  accountsChanged: 'accountsChanged',
@@ -91,13 +93,13 @@ class OneKeyNearProvider extends ProviderNearBase_1.ProviderNearBase {
91
93
  this._isUnlocked = false;
92
94
  this._initializedEmitted = false;
93
95
  if (!networkId) {
94
- throw new Error('OneKeyNearWallet init error: networkId required.');
96
+ // throw new Error('OneKeyNearWallet init error: networkId required.');
95
97
  }
96
98
  this._authDataKey = keyPrefix + this._authDataKey;
97
99
  this._enablePageReload = enablePageReload;
98
100
  this._connectEagerly = connectEagerly;
99
101
  this._connection = connection;
100
- this._networkId = networkId;
102
+ this._networkId = networkId || '';
101
103
  this._transactionCreator = transactionCreator || defaultTransactionCreator;
102
104
  this._initAuthDataFromStorage();
103
105
  this._registerEvents();
@@ -283,8 +285,8 @@ class OneKeyNearProvider extends ProviderNearBase_1.ProviderNearBase {
283
285
  return this.bridgeRequest(Object.assign(Object.assign({}, payload), { requestInfo: {
284
286
  accountId: this.getAccountId(),
285
287
  publicKey: this.getPublicKey(),
286
- networkId: this.getNetworkId(),
287
- selectedNetworkId: ((_a = this.getSelectedNetwork()) === null || _a === void 0 ? void 0 : _a.networkId) || '',
288
+ networkId: this._networkId,
289
+ selectedNetworkId: ((_a = this.getNetworkInfo()) === null || _a === void 0 ? void 0 : _a.networkId) || '',
288
290
  } }));
289
291
  }
290
292
  isInstalled() {
@@ -307,10 +309,7 @@ class OneKeyNearProvider extends ProviderNearBase_1.ProviderNearBase {
307
309
  getAccountInfo() {
308
310
  return this._authData || DEFAULT_AUTH_DATA;
309
311
  }
310
- getNetworkId() {
311
- return this._networkId || '';
312
- }
313
- getSelectedNetwork() {
312
+ getNetworkInfo() {
314
313
  return this._selectedNetwork;
315
314
  }
316
315
  _saveAuthData(data) {
@@ -401,7 +400,7 @@ class OneKeyNearProvider extends ProviderNearBase_1.ProviderNearBase {
401
400
  return res;
402
401
  });
403
402
  }
404
- requestSignMessages({ messages = [], meta = {} }) {
403
+ requestSignMessages({ messages = [], meta = {}, }) {
405
404
  return __awaiter(this, void 0, void 0, function* () {
406
405
  const res = yield this._callBridgeRequest({
407
406
  method: PROVIDER_METHODS.near_requestSignMessages,
@@ -415,7 +414,11 @@ class OneKeyNearProvider extends ProviderNearBase_1.ProviderNearBase {
415
414
  return __awaiter(this, void 0, void 0, function* () {
416
415
  const paramsArr = [].concat(params);
417
416
  const paramObj = paramsArr[0];
418
- if (method === PROVIDER_METHODS.near_requestSignIn) {
417
+ if (method === PROVIDER_METHODS.near_network) {
418
+ method = PROVIDER_METHODS.near_networkInfo;
419
+ }
420
+ if (method === PROVIDER_METHODS.near_requestAccounts ||
421
+ method === PROVIDER_METHODS.near_requestSignIn) {
419
422
  return this.requestSignIn(paramObj);
420
423
  }
421
424
  if (method === PROVIDER_METHODS.near_sendTransactions ||
@@ -431,6 +434,9 @@ class OneKeyNearProvider extends ProviderNearBase_1.ProviderNearBase {
431
434
  method === PROVIDER_METHODS.near_requestSignMessages) {
432
435
  return this.requestSignMessages(paramObj);
433
436
  }
437
+ if (method === PROVIDER_METHODS.near_signOut) {
438
+ return this.signOut();
439
+ }
434
440
  return yield this._callBridgeRequest({
435
441
  method,
436
442
  params,
@@ -442,7 +448,6 @@ class OneKeyNearProvider extends ProviderNearBase_1.ProviderNearBase {
442
448
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
443
449
  return provider.sendJsonRpc(method, params);
444
450
  }
445
- // SpecialWallet required
446
451
  createTransaction({ receiverId, actions, nonceOffset = 1 }) {
447
452
  return this.account().createTransaction({
448
453
  receiverId,
@@ -485,6 +490,7 @@ class OneKeyWalletAccount extends near_api_js_1.Account {
485
490
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
486
491
  // @ts-ignore
487
492
  signAndSendTransaction(signAndSendTransactionOptions) {
493
+ var _a;
488
494
  return __awaiter(this, arguments, void 0, function* () {
489
495
  let options = signAndSendTransactionOptions;
490
496
  // eslint-disable-next-line prefer-rest-params
@@ -502,12 +508,44 @@ class OneKeyWalletAccount extends near_api_js_1.Account {
502
508
  });
503
509
  const txHashList = yield this._wallet.requestSignTransactions({
504
510
  transactions: [transaction],
505
- meta: Object.assign({}, meta),
511
+ meta,
506
512
  callbackUrl,
507
513
  });
508
- // TODO return typeof this.connection.provider.sendTransaction
509
- // same type to pending tx polling result
510
- return txHashList;
514
+ const txHash = (_a = txHashList === null || txHashList === void 0 ? void 0 : txHashList.transactionHashes) === null || _a === void 0 ? void 0 : _a[0];
515
+ if (txHash) {
516
+ // near-api-js/lib/providers/json-rpc-provider.js
517
+ // async txStatus(txHash, accountId)
518
+ const txHashStr = typeof txHash === 'string' ? txHash : (0, borsh_1.baseEncode)(txHash);
519
+ const res = (yield this._wallet.request({
520
+ method: 'tx',
521
+ params: [txHashStr, this.accountId],
522
+ }));
523
+ return res;
524
+ }
525
+ throw cross_inpage_provider_errors_1.web3Errors.rpc.internal({
526
+ message: 'Transaction sign and send failed: transactionHash not found',
527
+ });
528
+ });
529
+ }
530
+ getAccessKeys() {
531
+ return __awaiter(this, void 0, void 0, function* () {
532
+ // near-api-js/lib/account.js
533
+ // async getAccessKeys() { ... }
534
+ const response = yield this._wallet.request({
535
+ method: 'query',
536
+ params: {
537
+ request_type: 'view_access_key_list',
538
+ account_id: this.accountId,
539
+ finality: 'optimistic',
540
+ },
541
+ });
542
+ // A breaking API change introduced extra information into the
543
+ // response, so it now returns an object with a `keys` field instead
544
+ // of an array: https://github.com/nearprotocol/nearcore/pull/1789
545
+ if (Array.isArray(response)) {
546
+ return response;
547
+ }
548
+ return response.keys;
511
549
  });
512
550
  }
513
551
  _fetchAccountAccessKey({ publicKey, accountId }) {
@@ -525,7 +563,7 @@ class OneKeyWalletAccount extends near_api_js_1.Account {
525
563
  throw new Error(`near account access key not found for: ${accountId}`);
526
564
  });
527
565
  }
528
- createTransaction({ receiverId, actions, nonceOffset = 1 }) {
566
+ createTransaction({ receiverId, actions, nonceOffset = 1, }) {
529
567
  return __awaiter(this, void 0, void 0, function* () {
530
568
  const _authData = this._wallet._authData;
531
569
  const publicKey = _authData.publicKey;
@@ -539,7 +577,12 @@ class OneKeyWalletAccount extends near_api_js_1.Account {
539
577
  publicKey,
540
578
  });
541
579
  const nonce = accessKeyInfo.accessKey.nonce + nonceOffset;
542
- const block = yield this.connection.provider.block({ finality: 'final' });
580
+ // near-api-js/lib/providers/json-rpc-provider.js
581
+ // async block(blockQuery) {...}
582
+ const block = (yield this._wallet.request({
583
+ method: 'block',
584
+ params: { block_id: undefined, finality: 'final' },
585
+ }));
543
586
  const blockHash = (0, borsh_1.baseDecode)(block.header.hash);
544
587
  const transaction = this._wallet._transactionCreator({
545
588
  accountId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/onekey-near-provider",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "keywords": [
5
5
  "cross-inpage-provider"
6
6
  ],
@@ -35,13 +35,13 @@
35
35
  "near-api-js": "^0.44.2"
36
36
  },
37
37
  "dependencies": {
38
- "@onekeyfe/cross-inpage-provider-core": "^0.0.4",
39
- "@onekeyfe/cross-inpage-provider-errors": "^0.0.4",
40
- "@onekeyfe/cross-inpage-provider-types": "^0.0.4",
41
- "@onekeyfe/extension-bridge-injected": "^0.0.4",
38
+ "@onekeyfe/cross-inpage-provider-core": "^0.0.5",
39
+ "@onekeyfe/cross-inpage-provider-errors": "^0.0.5",
40
+ "@onekeyfe/cross-inpage-provider-types": "^0.0.5",
41
+ "@onekeyfe/extension-bridge-injected": "^0.0.5",
42
42
  "borsh": "^0.6.0",
43
43
  "depd": "^2.0.0",
44
44
  "tweetnacl": "^1.0.3"
45
45
  },
46
- "gitHead": "d47447804157874b2607aea82f92ff3a132c5e67"
46
+ "gitHead": "fc053fe3c2920fca734addae381339a29a09b716"
47
47
  }