near-api-ts 0.7.1 → 0.9.0
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.
- package/README.md +1 -1
- package/browser/src/idbKeyService/idbKeyService.ts +8 -9
- package/browser/src/idbKeyService/private/getKeyPair.ts +3 -4
- package/browser/src/idbKeyService/public/addKey.ts +23 -24
- package/browser/src/idbKeyService/public/clear.ts +1 -1
- package/browser/src/idbKeyService/public/hasKey.ts +6 -7
- package/browser/src/idbKeyService/public/removeKey.ts +1 -1
- package/browser/src/idbKeyService/public/signTransaction.ts +43 -49
- package/browser/types/idbKeyService/idbKeyService.ts +4 -1
- package/browser/types/natError.ts +1 -1
- package/dist/browser/index.d.ts +1071 -769
- package/dist/browser/index.js +1251 -1129
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.d.ts +1071 -769
- package/dist/node/index.js +1268 -1149
- package/dist/node/index.js.map +1 -1
- package/dist/universal/index.d.ts +1314 -1012
- package/dist/universal/index.js +1226 -1096
- package/dist/universal/index.js.map +1 -1
- package/node/src/fileKeyService/fileKeyService.ts +6 -13
- package/node/src/fileKeyService/private/getKeyPair.ts +3 -4
- package/node/src/fileKeyService/public/addKeyPair.ts +3 -3
- package/node/src/fileKeyService/public/clear.ts +1 -1
- package/node/src/fileKeyService/public/hasKeyPair.ts +1 -1
- package/node/src/fileKeyService/public/removeKeyPair.ts +1 -1
- package/node/src/fileKeyService/public/signTransaction.ts +43 -49
- package/node/types/fileKeyService/fileKeyService.ts +4 -1
- package/node/types/natError.ts +1 -1
- package/package.json +35 -13
- package/universal/src/_common/configs/constants.ts +7 -0
- package/universal/src/_common/natError.ts +12 -10
- package/universal/src/_common/schemas/borsh/actions/actions.ts +30 -0
- package/universal/src/_common/schemas/borsh/actions/addKey.ts +3 -6
- package/universal/src/_common/schemas/borsh/actions/delegate.ts +7 -0
- package/universal/src/_common/schemas/borsh/actions/deleteKey.ts +2 -2
- package/universal/src/_common/schemas/borsh/actions/stake.ts +2 -2
- package/universal/src/_common/schemas/borsh/delegateAction.ts +18 -7
- package/universal/src/_common/schemas/borsh/nep413Message.ts +11 -0
- package/universal/src/_common/schemas/borsh/publicKey.ts +1 -1
- package/universal/src/_common/schemas/borsh/signature.ts +1 -1
- package/universal/src/_common/schemas/borsh/transaction.ts +9 -36
- package/universal/src/_common/schemas/zod/common/accessKey.ts +10 -0
- package/universal/src/_common/schemas/zod/common/base58String.ts +10 -0
- package/universal/src/_common/schemas/zod/common/base64String.ts +11 -0
- package/universal/src/_common/schemas/zod/common/common.ts +2 -6
- package/universal/src/_common/schemas/zod/common/cryptoHash.ts +1 -9
- package/universal/src/_common/schemas/zod/common/curveString.ts +1 -1
- package/universal/src/_common/schemas/zod/message.ts +32 -0
- package/universal/src/_common/schemas/zod/transaction/actions/addKey.ts +3 -6
- package/universal/src/_common/schemas/zod/transaction/actions/deleteAccount.ts +1 -3
- package/universal/src/_common/schemas/zod/transaction/actions/deployContract.ts +1 -3
- package/universal/src/_common/schemas/zod/transaction/transaction.ts +13 -7
- package/universal/src/_common/transformers/fromBorshBytes/delegation.ts +5 -0
- package/universal/src/_common/transformers/toBorshBytes/message.ts +13 -0
- package/universal/src/_common/transformers/toBorshBytes/transaction.ts +13 -11
- package/universal/src/_common/transformers/toCurveString.ts +2 -3
- package/universal/src/_common/transformers/toNative/actions/addKey.ts +4 -6
- package/universal/src/_common/transformers/toNative/actions/createAccount.ts +1 -1
- package/universal/src/_common/transformers/toNative/actions/deleteAccount.ts +1 -1
- package/universal/src/_common/transformers/toNative/actions/deleteKey.ts +2 -4
- package/universal/src/_common/transformers/toNative/actions/deployContract.ts +1 -1
- package/universal/src/_common/transformers/toNative/actions/functionCall.ts +2 -4
- package/universal/src/_common/transformers/toNative/actions/stake.ts +2 -4
- package/universal/src/_common/transformers/toNative/actions/transfer.ts +2 -4
- package/universal/src/_common/transformers/toNative/blockReference.ts +6 -19
- package/universal/src/_common/transformers/toNative/publicKey.ts +2 -5
- package/universal/src/_common/transformers/toNative/signature.ts +2 -5
- package/universal/src/_common/transformers/toNative/transaction.ts +14 -12
- package/universal/src/_common/utils/addTo.ts +1 -5
- package/universal/src/_common/utils/asThrowable.ts +1 -3
- package/universal/src/_common/utils/common.ts +3 -9
- package/universal/src/_common/utils/getTransactionHash.ts +1 -3
- package/universal/src/_common/utils/repackError.ts +1 -1
- package/universal/src/_common/utils/sleep.ts +1 -4
- package/universal/src/_common/utils/snakeToCamelCase.ts +1 -3
- package/universal/src/_common/utils/wrapInternalError.ts +1 -1
- package/universal/src/client/cache/getRecentBlockHash.ts +3 -11
- package/universal/src/client/cache/getStoragePricePerByte.ts +2 -6
- package/universal/src/client/createClient.ts +4 -8
- package/universal/src/client/methods/account/_common/transformAccessKey.ts +10 -16
- package/universal/src/client/methods/account/getAccountAccessKey/getAccountAccessKey.ts +11 -6
- package/universal/src/client/methods/account/getAccountAccessKey/handleError.ts +2 -7
- package/universal/src/client/methods/account/getAccountAccessKey/handleResult.ts +4 -11
- package/universal/src/client/methods/account/getAccountAccessKeys/getAccountAccessKeys.ts +11 -6
- package/universal/src/client/methods/account/getAccountAccessKeys/handleError.ts +2 -7
- package/universal/src/client/methods/account/getAccountAccessKeys/handleResult.ts +4 -11
- package/universal/src/client/methods/account/getAccountInfo/getAccountInfo.ts +10 -3
- package/universal/src/client/methods/account/getAccountInfo/handleError.ts +2 -7
- package/universal/src/client/methods/account/getAccountInfo/handleResult/calculateAccountBalance.ts +2 -4
- package/universal/src/client/methods/account/getAccountInfo/handleResult/handleResult.ts +8 -10
- package/universal/src/client/methods/block/getBlock/getBlock.ts +35 -31
- package/universal/src/client/methods/block/getBlock/handleError.ts +1 -3
- package/universal/src/client/methods/contract/callContractReadFunction/callContractReadFunction.ts +44 -44
- package/universal/src/client/methods/contract/callContractReadFunction/handleError.ts +2 -7
- package/universal/src/client/methods/contract/callContractReadFunction/handleResult/deserializeCallResult.ts +23 -14
- package/universal/src/client/methods/contract/callContractReadFunction/handleResult/handleResult.ts +4 -9
- package/universal/src/client/methods/contract/callContractReadFunction/serializeFunctionArgs.ts +30 -28
- package/universal/src/client/methods/contract/getContractState.ts +8 -10
- package/universal/src/client/methods/protocol/getGasPrice.ts +7 -5
- package/universal/src/client/methods/protocol/getProtocolConfig.ts +7 -5
- package/universal/src/client/methods/transaction/sendSignedTransaction/handleError/handleError.ts +2 -5
- package/universal/src/client/methods/transaction/sendSignedTransaction/handleError/handleInvalidTransaction.ts +1 -3
- package/universal/src/client/methods/transaction/sendSignedTransaction/handleResult/handleActionError.ts +1 -1
- package/universal/src/client/methods/transaction/sendSignedTransaction/handleResult/handleResult.ts +4 -13
- package/universal/src/client/methods/transaction/sendSignedTransaction/sendSignedTransaction.ts +37 -38
- package/universal/src/client/transport/createTransport.ts +6 -5
- package/universal/src/client/transport/sendRequest/1-createSendRequest/_common/getAvailableRpcs.ts +13 -15
- package/universal/src/client/transport/sendRequest/1-createSendRequest/createRequestTimeout.ts +1 -1
- package/universal/src/client/transport/sendRequest/1-createSendRequest/createSendRequest.ts +6 -5
- package/universal/src/client/transport/sendRequest/1-createSendRequest/handleMaybeUnknownBlock.ts +2 -2
- package/universal/src/client/transport/sendRequest/2-tryMultipleRounds/tryMultipleRounds.ts +4 -8
- package/universal/src/client/transport/sendRequest/3-tryOneRound/tryOneRound.ts +4 -8
- package/universal/src/client/transport/sendRequest/4-sendWithRetry/sendWithRetry.ts +6 -13
- package/universal/src/client/transport/sendRequest/5-sendOnce/extractRpcErrors.ts +4 -8
- package/universal/src/client/transport/sendRequest/5-sendOnce/fetchData/createAttemptTimeout.ts +1 -1
- package/universal/src/client/transport/sendRequest/5-sendOnce/fetchData/fetchData.ts +5 -7
- package/universal/src/client/transport/sendRequest/5-sendOnce/parseJsonResponse.ts +4 -5
- package/universal/src/client/transport/sendRequest/5-sendOnce/sendOnce.ts +3 -3
- package/universal/src/client/transport/transportPolicy.ts +6 -13
- package/universal/src/helpers/actionCreators/addFullAccessKey.ts +9 -4
- package/universal/src/helpers/actionCreators/addFunctionCallKey.ts +15 -10
- package/universal/src/helpers/actionCreators/createAccount.ts +1 -1
- package/universal/src/helpers/actionCreators/deleteAccount.ts +10 -6
- package/universal/src/helpers/actionCreators/deleteKey.ts +5 -3
- package/universal/src/helpers/actionCreators/deployContract.ts +11 -8
- package/universal/src/helpers/actionCreators/functionCall.ts +38 -25
- package/universal/src/helpers/actionCreators/sponsor.ts +0 -0
- package/universal/src/helpers/actionCreators/stake.ts +4 -1
- package/universal/src/helpers/actionCreators/transfer.ts +5 -3
- package/universal/src/helpers/keyPair/_common/signByEd25519Key.ts +2 -3
- package/universal/src/helpers/keyPair/_common/signBySecp256k1Key.ts +7 -7
- package/universal/src/helpers/keyPair/getInnerPublicKey.ts +29 -0
- package/universal/src/helpers/keyPair/keyPair.ts +19 -15
- package/universal/src/helpers/keyPair/randomEd25519KeyPair.ts +20 -13
- package/universal/src/helpers/keyPair/randomSecp256k1KeyPair.ts +24 -19
- package/universal/src/helpers/message/createMessage.ts +43 -0
- package/universal/src/helpers/message/verifyMessage.ts +67 -0
- package/universal/src/helpers/nearGas.ts +20 -9
- package/universal/src/helpers/tokens/nearToken.ts +27 -30
- package/universal/src/helpers/tokens/tokenConverter/convertTokensToUnits.ts +4 -11
- package/universal/src/helpers/tokens/tokenConverter/convertUnitsToTokens.ts +1 -4
- package/universal/src/helpers/verifySignature.ts +59 -0
- package/universal/src/keyServices/memoryKeyService/createFindKeyPair.ts +1 -3
- package/universal/src/keyServices/memoryKeyService/createMemoryKeyService.ts +17 -10
- package/universal/src/keyServices/memoryKeyService/createSignTransaction.ts +37 -43
- package/universal/src/keyServices/memoryKeyService/getKeyPairs.ts +1 -3
- package/universal/src/signers/memorySigner/createExecuteTransaction.ts +54 -61
- package/universal/src/signers/memorySigner/createMemorySigner.ts +8 -7
- package/universal/src/signers/memorySigner/createSignTransaction.ts +1 -3
- package/universal/src/signers/memorySigner/keyPool/createFindKeyForTask.ts +11 -5
- package/universal/src/signers/memorySigner/keyPool/createGetPoolKeys/createFullAccessPoolKeys.ts +7 -5
- package/universal/src/signers/memorySigner/keyPool/createGetPoolKeys/createFunctionCallPoolKeys.ts +9 -10
- package/universal/src/signers/memorySigner/keyPool/createGetPoolKeys/createGetPoolKeys.ts +12 -14
- package/universal/src/signers/memorySigner/keyPool/createGetPoolKeys/getAllowedAccessKeys.ts +2 -2
- package/universal/src/signers/memorySigner/keyPool/createGetPoolKeys/keyUtils.ts +2 -2
- package/universal/src/signers/memorySigner/keyPool/createIsKeyForTaskExist.ts +12 -7
- package/universal/src/signers/memorySigner/keyPool/createKeyPool.ts +6 -10
- package/universal/src/signers/memorySigner/taskQueue/createFindTaskForKey.ts +11 -11
- package/universal/src/signers/memorySigner/taskQueue/createTaskQueue.ts +8 -6
- package/universal/src/signers/memorySigner/taskQueue/taskCreators/_common/addTask.ts +5 -4
- package/universal/src/signers/memorySigner/taskQueue/taskCreators/_common/getAccessTypePriority.ts +4 -4
- package/universal/src/signers/memorySigner/taskQueue/taskCreators/createAddExecuteTransactionTask.ts +1 -1
- package/universal/src/signers/memorySigner/taskQueue/taskCreators/createAddSignTransactionTask.ts +1 -1
- package/universal/src/signers/memorySigner/tasker/createTasker.ts +9 -6
- package/universal/src/signers/memorySigner/tasker/executeTask/executeTask.ts +5 -5
- package/universal/src/signers/memorySigner/tasker/executeTask/executors/executeTransaction.ts +8 -12
- package/universal/src/signers/memorySigner/tasker/executeTask/executors/signTransaction.ts +25 -25
- package/universal/types/_common/Uint8Array.ts +77 -0
- package/universal/types/_common/accountAccessKey.ts +41 -3
- package/universal/types/_common/common.ts +5 -17
- package/universal/types/_common/keyPair/keyPair.ts +8 -7
- package/universal/types/_common/keyPair/randomEd25519KeyPair.ts +7 -5
- package/universal/types/_common/keyPair/randomSecp256k1KeyPair.ts +7 -5
- package/universal/types/_common/message.ts +74 -0
- package/universal/types/{natError.ts → _common/natError.ts} +18 -16
- package/universal/types/_common/nearGas.ts +2 -4
- package/universal/types/_common/nearToken.ts +7 -19
- package/universal/types/_common/transaction/actions/actions.ts +18 -0
- package/universal/types/{actions → _common/transaction/actions}/addKey.ts +11 -11
- package/universal/types/{actions → _common/transaction/actions}/deleteAccount.ts +3 -3
- package/universal/types/{actions → _common/transaction/actions}/deleteKey.ts +5 -7
- package/universal/types/{actions → _common/transaction/actions}/deployContract.ts +3 -3
- package/universal/types/{actions → _common/transaction/actions}/functionCall.ts +16 -24
- package/universal/types/_common/transaction/actions/sponsor.ts +77 -0
- package/universal/types/{actions → _common/transaction/actions}/stake.ts +5 -6
- package/universal/types/{actions → _common/transaction/actions}/transfer.ts +5 -7
- package/universal/types/_common/transaction/delegation.ts +52 -0
- package/universal/types/_common/transaction/rpcTransactionErrorContext.ts +1 -1
- package/universal/types/_common/transaction/transaction.ts +24 -19
- package/universal/types/_common/verifySignature.ts +27 -0
- package/universal/types/client/cache/getRecentBlockHash.ts +7 -5
- package/universal/types/client/client.ts +31 -8
- package/universal/types/client/createClient.ts +2 -4
- package/universal/types/client/methods/_common/common.ts +1 -1
- package/universal/types/client/methods/account/getAccountAccessKey.ts +22 -6
- package/universal/types/client/methods/account/getAccountAccessKeys.ts +22 -6
- package/universal/types/client/methods/account/getAccountInfo.ts +25 -12
- package/universal/types/client/methods/block/getBlock.ts +9 -6
- package/universal/types/client/methods/contract/callContractReadFunction.ts +69 -56
- package/universal/types/client/methods/contract/getContractState.ts +9 -7
- package/universal/types/client/methods/protocol/getGasPrice.ts +1 -3
- package/universal/types/client/methods/protocol/getProtocolConfig.ts +3 -7
- package/universal/types/client/methods/transaction/sendSignedTransaction.ts +9 -4
- package/universal/types/client/transport/sendRequest.ts +13 -9
- package/universal/types/keyServices/memoryKeyService/createFindKeyPair.ts +1 -3
- package/universal/types/keyServices/memoryKeyService/createMemoryKeyService.ts +1 -3
- package/universal/types/keyServices/memoryKeyService/createSignTransaction.ts +1 -3
- package/universal/types/keyServices/memoryKeyService/memoryKeyService.ts +1 -1
- package/universal/types/signers/memorySigner/_common/errorContext.ts +6 -6
- package/universal/types/signers/memorySigner/inner/keyPool.ts +3 -5
- package/universal/types/signers/memorySigner/inner/taskQueue.ts +18 -8
- package/universal/types/signers/memorySigner/inner/tasker.ts +2 -7
- package/universal/types/signers/memorySigner/memorySigner.ts +11 -3
- package/universal/types/signers/memorySigner/public/createExecuteTransaction.ts +11 -8
- package/universal/types/signers/memorySigner/public/createMemorySigner.ts +2 -2
- package/universal/types/signers/memorySigner/public/createSignTransaction.ts +9 -10
- package/universal/src/_common/schemas/borsh/actions/signedDelegate.ts +0 -13
- package/universal/src/_common/schemas/borsh/index.ts +0 -2
- package/universal/types/actions/actions.ts +0 -16
- /package/universal/types/{actions → _common/transaction/actions}/createAccount.ts +0 -0
package/README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// import * as z from 'zod/mini';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import type {
|
|
2
|
+
|
|
3
|
+
import type { PublicKey } from '../../../universal';
|
|
4
|
+
import { asThrowable } from '../../../universal/src/_common/utils/asThrowable';
|
|
5
|
+
import { result } from '../../../universal/src/_common/utils/result';
|
|
6
|
+
import { wrapInternalError } from '../../../universal/src/_common/utils/wrapInternalError';
|
|
7
|
+
import type { Result } from '../../../universal/types/_common/common';
|
|
8
|
+
import type { KeyPair } from '../../../universal/types/_common/keyPair/keyPair';
|
|
8
9
|
import { createGetKeyPair } from './private/getKeyPair';
|
|
9
10
|
import { openIdbConnection } from './private/openIdbConnection';
|
|
10
11
|
import { createSafeAddKey } from './public/addKey';
|
|
@@ -56,6 +57,4 @@ export const safeCreateIdbKeyService: any = wrapInternalError(
|
|
|
56
57
|
},
|
|
57
58
|
);
|
|
58
59
|
|
|
59
|
-
export const throwableCreateIdbKeyService: any = asThrowable(
|
|
60
|
-
safeCreateIdbKeyService,
|
|
61
|
-
);
|
|
60
|
+
export const throwableCreateIdbKeyService: any = asThrowable(safeCreateIdbKeyService);
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { safeKeyPair } from '
|
|
2
|
-
import { result } from '
|
|
1
|
+
import { safeKeyPair } from '../../../../universal';
|
|
2
|
+
import { result } from '../../../../universal/src/_common/utils/result';
|
|
3
3
|
import type { IdbKeyServiceContext } from '../idbKeyService';
|
|
4
4
|
|
|
5
5
|
export const createGetKeyPair =
|
|
6
6
|
(context: IdbKeyServiceContext) =>
|
|
7
7
|
async (publicKey: any): Promise<any> => {
|
|
8
8
|
// 1. If the key pair is already in the cache, return it
|
|
9
|
-
if (context.keyPairs.has(publicKey))
|
|
10
|
-
return result.ok(context.keyPairs.get(publicKey));
|
|
9
|
+
if (context.keyPairs.has(publicKey)) return result.ok(context.keyPairs.get(publicKey));
|
|
11
10
|
|
|
12
11
|
if (!context.idb) return result.err(false); // TODO wait until idb is ready
|
|
13
12
|
|
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import { keyPair } from '
|
|
2
|
-
import { result } from '
|
|
1
|
+
import { keyPair } from '../../../../universal/index';
|
|
2
|
+
import { result } from '../../../../universal/src/_common/utils/result';
|
|
3
3
|
import type { IdbKeyServiceContext } from '../idbKeyService';
|
|
4
4
|
|
|
5
|
-
export const createSafeAddKey =
|
|
6
|
-
(context
|
|
7
|
-
if (!context.idb) return result.err(false); // TODO wait until idb is ready
|
|
5
|
+
export const createSafeAddKey = (context: IdbKeyServiceContext) => async (args: any) => {
|
|
6
|
+
if (!context.idb) return result.err(false); // TODO wait until idb is ready
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
const kp = keyPair(args.privateKey);
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
// 2. Put the private key to the Idb
|
|
11
|
+
const request = context.idb
|
|
12
|
+
.transaction(['keyPairs'], 'readwrite')
|
|
13
|
+
.objectStore('keyPairs')
|
|
14
|
+
.put(kp.privateKey, kp.publicKey);
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
await new Promise((resolve, reject) => {
|
|
17
|
+
request.onsuccess = () => {
|
|
18
|
+
console.log('Key added', request.result);
|
|
19
|
+
context.keyPairs.set(kp.publicKey, kp);
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
resolve(result.ok(request.result));
|
|
22
|
+
};
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
request.onerror = () => {
|
|
25
|
+
console.log('Error while adding key', request.error);
|
|
26
|
+
reject(request.error);
|
|
27
|
+
};
|
|
28
|
+
});
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
return result.ok(kp);
|
|
31
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { result } from '
|
|
1
|
+
import { result } from '../../../../universal/src/_common/utils/result';
|
|
2
2
|
import type { IdbKeyServiceContext } from '../idbKeyService';
|
|
3
3
|
|
|
4
4
|
export const createSafeClear = (context: IdbKeyServiceContext) => async () => {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { result } from '
|
|
1
|
+
import { result } from '../../../../universal/src/_common/utils/result';
|
|
2
2
|
import type { IdbKeyServiceContext } from '../idbKeyService';
|
|
3
3
|
|
|
4
|
-
export const createSafeHasKey =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
4
|
+
export const createSafeHasKey = (context: IdbKeyServiceContext) => async (args: any) => {
|
|
5
|
+
const keyPair = await context.getKeyPair(args.publicKey);
|
|
6
|
+
/// TODO rework
|
|
7
|
+
return result.ok(keyPair.ok);
|
|
8
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createNatError } from '@universal/src/_common/natError';
|
|
2
|
-
import { TransactionSchema } from '@universal/src/_common/schemas/zod/transaction/transaction';
|
|
3
|
-
import { getTransactionHash } from '@universal/src/_common/utils/getTransactionHash';
|
|
4
|
-
import { result } from '@universal/src/_common/utils/result';
|
|
5
|
-
import { wrapInternalError } from '@universal/src/_common/utils/wrapInternalError';
|
|
6
1
|
import * as z from 'zod/mini';
|
|
2
|
+
import { createNatError } from '../../../../universal/src/_common/natError';
|
|
3
|
+
import { TransactionSchema } from '../../../../universal/src/_common/schemas/zod/transaction/transaction';
|
|
4
|
+
import { getTransactionHash } from '../../../../universal/src/_common/utils/getTransactionHash';
|
|
5
|
+
import { result } from '../../../../universal/src/_common/utils/result';
|
|
6
|
+
import { wrapInternalError } from '../../../../universal/src/_common/utils/wrapInternalError';
|
|
7
7
|
import type { IdbKeyServiceContext } from '../idbKeyService';
|
|
8
8
|
|
|
9
9
|
const SignTransactionArgsSchema = z.object({
|
|
@@ -11,49 +11,43 @@ const SignTransactionArgsSchema = z.object({
|
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
export const createSafeSignTransaction: any = (context: IdbKeyServiceContext) =>
|
|
14
|
-
wrapInternalError(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
context: { zodError: validArgs.error },
|
|
24
|
-
}),
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
const { transaction: innerTransaction } = validArgs.data;
|
|
28
|
-
|
|
29
|
-
const keyPair = await context.getKeyPair(
|
|
30
|
-
innerTransaction.signerPublicKey.publicKey,
|
|
14
|
+
wrapInternalError(`IdbKeyService.SignTransaction.Internal`, async (args: any) => {
|
|
15
|
+
const validArgs = SignTransactionArgsSchema.safeParse(args);
|
|
16
|
+
|
|
17
|
+
if (!validArgs.success)
|
|
18
|
+
return result.err(
|
|
19
|
+
createNatError({
|
|
20
|
+
kind: `IdbKeyService.SignTransaction.Args.InvalidSchema`,
|
|
21
|
+
context: { zodError: validArgs.error },
|
|
22
|
+
}),
|
|
31
23
|
);
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
25
|
+
const { transaction: innerTransaction } = validArgs.data;
|
|
26
|
+
|
|
27
|
+
const keyPair = await context.getKeyPair(innerTransaction.signerPublicKey.publicKey);
|
|
28
|
+
|
|
29
|
+
// TODO Think if it's possible to wrap into some helper function
|
|
30
|
+
if (!keyPair.ok) {
|
|
31
|
+
// if (keyPair.error.kind === 'MemoryKeyService.FindKeyPair.NotFound')
|
|
32
|
+
// return result.err(
|
|
33
|
+
// createNatError({
|
|
34
|
+
// kind: 'MemoryKeyService.SignTransaction.SigningKeyPair.NotFound',
|
|
35
|
+
// context: {
|
|
36
|
+
// signerPublicKey: innerTransaction.signerPublicKey.publicKey,
|
|
37
|
+
// },
|
|
38
|
+
// }),
|
|
39
|
+
// );
|
|
40
|
+
console.log(keyPair);
|
|
41
|
+
throw keyPair.error;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const { transactionHash, u8TransactionHash } = getTransactionHash(innerTransaction);
|
|
45
|
+
|
|
46
|
+
const { signature } = keyPair.value.sign(u8TransactionHash); // todo make async?
|
|
47
|
+
|
|
48
|
+
return result.ok({
|
|
49
|
+
transaction: args.transaction,
|
|
50
|
+
transactionHash,
|
|
51
|
+
signature,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
InternalErrorContext,
|
|
3
|
+
InvalidSchemaErrorContext,
|
|
4
|
+
} from '../../../universal/types/_common/natError';
|
|
2
5
|
|
|
3
6
|
export interface IdbKeyServicePublicErrorRegister {
|
|
4
7
|
'CreateIdbKeyService.Internal': InternalErrorContext;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IdbKeyServicePublicErrorRegister } from './idbKeyService/idbKeyService';
|
|
2
2
|
|
|
3
|
-
declare module '
|
|
3
|
+
declare module '../../universal/types/_common/natError' {
|
|
4
4
|
interface NatPublicErrorRegistry extends IdbKeyServicePublicErrorRegister {}
|
|
5
5
|
}
|