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.
Files changed (220) hide show
  1. package/README.md +1 -1
  2. package/browser/src/idbKeyService/idbKeyService.ts +8 -9
  3. package/browser/src/idbKeyService/private/getKeyPair.ts +3 -4
  4. package/browser/src/idbKeyService/public/addKey.ts +23 -24
  5. package/browser/src/idbKeyService/public/clear.ts +1 -1
  6. package/browser/src/idbKeyService/public/hasKey.ts +6 -7
  7. package/browser/src/idbKeyService/public/removeKey.ts +1 -1
  8. package/browser/src/idbKeyService/public/signTransaction.ts +43 -49
  9. package/browser/types/idbKeyService/idbKeyService.ts +4 -1
  10. package/browser/types/natError.ts +1 -1
  11. package/dist/browser/index.d.ts +1071 -769
  12. package/dist/browser/index.js +1251 -1129
  13. package/dist/browser/index.js.map +1 -1
  14. package/dist/node/index.d.ts +1071 -769
  15. package/dist/node/index.js +1268 -1149
  16. package/dist/node/index.js.map +1 -1
  17. package/dist/universal/index.d.ts +1314 -1012
  18. package/dist/universal/index.js +1226 -1096
  19. package/dist/universal/index.js.map +1 -1
  20. package/node/src/fileKeyService/fileKeyService.ts +6 -13
  21. package/node/src/fileKeyService/private/getKeyPair.ts +3 -4
  22. package/node/src/fileKeyService/public/addKeyPair.ts +3 -3
  23. package/node/src/fileKeyService/public/clear.ts +1 -1
  24. package/node/src/fileKeyService/public/hasKeyPair.ts +1 -1
  25. package/node/src/fileKeyService/public/removeKeyPair.ts +1 -1
  26. package/node/src/fileKeyService/public/signTransaction.ts +43 -49
  27. package/node/types/fileKeyService/fileKeyService.ts +4 -1
  28. package/node/types/natError.ts +1 -1
  29. package/package.json +35 -13
  30. package/universal/src/_common/configs/constants.ts +7 -0
  31. package/universal/src/_common/natError.ts +12 -10
  32. package/universal/src/_common/schemas/borsh/actions/actions.ts +30 -0
  33. package/universal/src/_common/schemas/borsh/actions/addKey.ts +3 -6
  34. package/universal/src/_common/schemas/borsh/actions/delegate.ts +7 -0
  35. package/universal/src/_common/schemas/borsh/actions/deleteKey.ts +2 -2
  36. package/universal/src/_common/schemas/borsh/actions/stake.ts +2 -2
  37. package/universal/src/_common/schemas/borsh/delegateAction.ts +18 -7
  38. package/universal/src/_common/schemas/borsh/nep413Message.ts +11 -0
  39. package/universal/src/_common/schemas/borsh/publicKey.ts +1 -1
  40. package/universal/src/_common/schemas/borsh/signature.ts +1 -1
  41. package/universal/src/_common/schemas/borsh/transaction.ts +9 -36
  42. package/universal/src/_common/schemas/zod/common/accessKey.ts +10 -0
  43. package/universal/src/_common/schemas/zod/common/base58String.ts +10 -0
  44. package/universal/src/_common/schemas/zod/common/base64String.ts +11 -0
  45. package/universal/src/_common/schemas/zod/common/common.ts +2 -6
  46. package/universal/src/_common/schemas/zod/common/cryptoHash.ts +1 -9
  47. package/universal/src/_common/schemas/zod/common/curveString.ts +1 -1
  48. package/universal/src/_common/schemas/zod/message.ts +32 -0
  49. package/universal/src/_common/schemas/zod/transaction/actions/addKey.ts +3 -6
  50. package/universal/src/_common/schemas/zod/transaction/actions/deleteAccount.ts +1 -3
  51. package/universal/src/_common/schemas/zod/transaction/actions/deployContract.ts +1 -3
  52. package/universal/src/_common/schemas/zod/transaction/transaction.ts +13 -7
  53. package/universal/src/_common/transformers/fromBorshBytes/delegation.ts +5 -0
  54. package/universal/src/_common/transformers/toBorshBytes/message.ts +13 -0
  55. package/universal/src/_common/transformers/toBorshBytes/transaction.ts +13 -11
  56. package/universal/src/_common/transformers/toCurveString.ts +2 -3
  57. package/universal/src/_common/transformers/toNative/actions/addKey.ts +4 -6
  58. package/universal/src/_common/transformers/toNative/actions/createAccount.ts +1 -1
  59. package/universal/src/_common/transformers/toNative/actions/deleteAccount.ts +1 -1
  60. package/universal/src/_common/transformers/toNative/actions/deleteKey.ts +2 -4
  61. package/universal/src/_common/transformers/toNative/actions/deployContract.ts +1 -1
  62. package/universal/src/_common/transformers/toNative/actions/functionCall.ts +2 -4
  63. package/universal/src/_common/transformers/toNative/actions/stake.ts +2 -4
  64. package/universal/src/_common/transformers/toNative/actions/transfer.ts +2 -4
  65. package/universal/src/_common/transformers/toNative/blockReference.ts +6 -19
  66. package/universal/src/_common/transformers/toNative/publicKey.ts +2 -5
  67. package/universal/src/_common/transformers/toNative/signature.ts +2 -5
  68. package/universal/src/_common/transformers/toNative/transaction.ts +14 -12
  69. package/universal/src/_common/utils/addTo.ts +1 -5
  70. package/universal/src/_common/utils/asThrowable.ts +1 -3
  71. package/universal/src/_common/utils/common.ts +3 -9
  72. package/universal/src/_common/utils/getTransactionHash.ts +1 -3
  73. package/universal/src/_common/utils/repackError.ts +1 -1
  74. package/universal/src/_common/utils/sleep.ts +1 -4
  75. package/universal/src/_common/utils/snakeToCamelCase.ts +1 -3
  76. package/universal/src/_common/utils/wrapInternalError.ts +1 -1
  77. package/universal/src/client/cache/getRecentBlockHash.ts +3 -11
  78. package/universal/src/client/cache/getStoragePricePerByte.ts +2 -6
  79. package/universal/src/client/createClient.ts +4 -8
  80. package/universal/src/client/methods/account/_common/transformAccessKey.ts +10 -16
  81. package/universal/src/client/methods/account/getAccountAccessKey/getAccountAccessKey.ts +11 -6
  82. package/universal/src/client/methods/account/getAccountAccessKey/handleError.ts +2 -7
  83. package/universal/src/client/methods/account/getAccountAccessKey/handleResult.ts +4 -11
  84. package/universal/src/client/methods/account/getAccountAccessKeys/getAccountAccessKeys.ts +11 -6
  85. package/universal/src/client/methods/account/getAccountAccessKeys/handleError.ts +2 -7
  86. package/universal/src/client/methods/account/getAccountAccessKeys/handleResult.ts +4 -11
  87. package/universal/src/client/methods/account/getAccountInfo/getAccountInfo.ts +10 -3
  88. package/universal/src/client/methods/account/getAccountInfo/handleError.ts +2 -7
  89. package/universal/src/client/methods/account/getAccountInfo/handleResult/calculateAccountBalance.ts +2 -4
  90. package/universal/src/client/methods/account/getAccountInfo/handleResult/handleResult.ts +8 -10
  91. package/universal/src/client/methods/block/getBlock/getBlock.ts +35 -31
  92. package/universal/src/client/methods/block/getBlock/handleError.ts +1 -3
  93. package/universal/src/client/methods/contract/callContractReadFunction/callContractReadFunction.ts +44 -44
  94. package/universal/src/client/methods/contract/callContractReadFunction/handleError.ts +2 -7
  95. package/universal/src/client/methods/contract/callContractReadFunction/handleResult/deserializeCallResult.ts +23 -14
  96. package/universal/src/client/methods/contract/callContractReadFunction/handleResult/handleResult.ts +4 -9
  97. package/universal/src/client/methods/contract/callContractReadFunction/serializeFunctionArgs.ts +30 -28
  98. package/universal/src/client/methods/contract/getContractState.ts +8 -10
  99. package/universal/src/client/methods/protocol/getGasPrice.ts +7 -5
  100. package/universal/src/client/methods/protocol/getProtocolConfig.ts +7 -5
  101. package/universal/src/client/methods/transaction/sendSignedTransaction/handleError/handleError.ts +2 -5
  102. package/universal/src/client/methods/transaction/sendSignedTransaction/handleError/handleInvalidTransaction.ts +1 -3
  103. package/universal/src/client/methods/transaction/sendSignedTransaction/handleResult/handleActionError.ts +1 -1
  104. package/universal/src/client/methods/transaction/sendSignedTransaction/handleResult/handleResult.ts +4 -13
  105. package/universal/src/client/methods/transaction/sendSignedTransaction/sendSignedTransaction.ts +37 -38
  106. package/universal/src/client/transport/createTransport.ts +6 -5
  107. package/universal/src/client/transport/sendRequest/1-createSendRequest/_common/getAvailableRpcs.ts +13 -15
  108. package/universal/src/client/transport/sendRequest/1-createSendRequest/createRequestTimeout.ts +1 -1
  109. package/universal/src/client/transport/sendRequest/1-createSendRequest/createSendRequest.ts +6 -5
  110. package/universal/src/client/transport/sendRequest/1-createSendRequest/handleMaybeUnknownBlock.ts +2 -2
  111. package/universal/src/client/transport/sendRequest/2-tryMultipleRounds/tryMultipleRounds.ts +4 -8
  112. package/universal/src/client/transport/sendRequest/3-tryOneRound/tryOneRound.ts +4 -8
  113. package/universal/src/client/transport/sendRequest/4-sendWithRetry/sendWithRetry.ts +6 -13
  114. package/universal/src/client/transport/sendRequest/5-sendOnce/extractRpcErrors.ts +4 -8
  115. package/universal/src/client/transport/sendRequest/5-sendOnce/fetchData/createAttemptTimeout.ts +1 -1
  116. package/universal/src/client/transport/sendRequest/5-sendOnce/fetchData/fetchData.ts +5 -7
  117. package/universal/src/client/transport/sendRequest/5-sendOnce/parseJsonResponse.ts +4 -5
  118. package/universal/src/client/transport/sendRequest/5-sendOnce/sendOnce.ts +3 -3
  119. package/universal/src/client/transport/transportPolicy.ts +6 -13
  120. package/universal/src/helpers/actionCreators/addFullAccessKey.ts +9 -4
  121. package/universal/src/helpers/actionCreators/addFunctionCallKey.ts +15 -10
  122. package/universal/src/helpers/actionCreators/createAccount.ts +1 -1
  123. package/universal/src/helpers/actionCreators/deleteAccount.ts +10 -6
  124. package/universal/src/helpers/actionCreators/deleteKey.ts +5 -3
  125. package/universal/src/helpers/actionCreators/deployContract.ts +11 -8
  126. package/universal/src/helpers/actionCreators/functionCall.ts +38 -25
  127. package/universal/src/helpers/actionCreators/sponsor.ts +0 -0
  128. package/universal/src/helpers/actionCreators/stake.ts +4 -1
  129. package/universal/src/helpers/actionCreators/transfer.ts +5 -3
  130. package/universal/src/helpers/keyPair/_common/signByEd25519Key.ts +2 -3
  131. package/universal/src/helpers/keyPair/_common/signBySecp256k1Key.ts +7 -7
  132. package/universal/src/helpers/keyPair/getInnerPublicKey.ts +29 -0
  133. package/universal/src/helpers/keyPair/keyPair.ts +19 -15
  134. package/universal/src/helpers/keyPair/randomEd25519KeyPair.ts +20 -13
  135. package/universal/src/helpers/keyPair/randomSecp256k1KeyPair.ts +24 -19
  136. package/universal/src/helpers/message/createMessage.ts +43 -0
  137. package/universal/src/helpers/message/verifyMessage.ts +67 -0
  138. package/universal/src/helpers/nearGas.ts +20 -9
  139. package/universal/src/helpers/tokens/nearToken.ts +27 -30
  140. package/universal/src/helpers/tokens/tokenConverter/convertTokensToUnits.ts +4 -11
  141. package/universal/src/helpers/tokens/tokenConverter/convertUnitsToTokens.ts +1 -4
  142. package/universal/src/helpers/verifySignature.ts +59 -0
  143. package/universal/src/keyServices/memoryKeyService/createFindKeyPair.ts +1 -3
  144. package/universal/src/keyServices/memoryKeyService/createMemoryKeyService.ts +17 -10
  145. package/universal/src/keyServices/memoryKeyService/createSignTransaction.ts +37 -43
  146. package/universal/src/keyServices/memoryKeyService/getKeyPairs.ts +1 -3
  147. package/universal/src/signers/memorySigner/createExecuteTransaction.ts +54 -61
  148. package/universal/src/signers/memorySigner/createMemorySigner.ts +8 -7
  149. package/universal/src/signers/memorySigner/createSignTransaction.ts +1 -3
  150. package/universal/src/signers/memorySigner/keyPool/createFindKeyForTask.ts +11 -5
  151. package/universal/src/signers/memorySigner/keyPool/createGetPoolKeys/createFullAccessPoolKeys.ts +7 -5
  152. package/universal/src/signers/memorySigner/keyPool/createGetPoolKeys/createFunctionCallPoolKeys.ts +9 -10
  153. package/universal/src/signers/memorySigner/keyPool/createGetPoolKeys/createGetPoolKeys.ts +12 -14
  154. package/universal/src/signers/memorySigner/keyPool/createGetPoolKeys/getAllowedAccessKeys.ts +2 -2
  155. package/universal/src/signers/memorySigner/keyPool/createGetPoolKeys/keyUtils.ts +2 -2
  156. package/universal/src/signers/memorySigner/keyPool/createIsKeyForTaskExist.ts +12 -7
  157. package/universal/src/signers/memorySigner/keyPool/createKeyPool.ts +6 -10
  158. package/universal/src/signers/memorySigner/taskQueue/createFindTaskForKey.ts +11 -11
  159. package/universal/src/signers/memorySigner/taskQueue/createTaskQueue.ts +8 -6
  160. package/universal/src/signers/memorySigner/taskQueue/taskCreators/_common/addTask.ts +5 -4
  161. package/universal/src/signers/memorySigner/taskQueue/taskCreators/_common/getAccessTypePriority.ts +4 -4
  162. package/universal/src/signers/memorySigner/taskQueue/taskCreators/createAddExecuteTransactionTask.ts +1 -1
  163. package/universal/src/signers/memorySigner/taskQueue/taskCreators/createAddSignTransactionTask.ts +1 -1
  164. package/universal/src/signers/memorySigner/tasker/createTasker.ts +9 -6
  165. package/universal/src/signers/memorySigner/tasker/executeTask/executeTask.ts +5 -5
  166. package/universal/src/signers/memorySigner/tasker/executeTask/executors/executeTransaction.ts +8 -12
  167. package/universal/src/signers/memorySigner/tasker/executeTask/executors/signTransaction.ts +25 -25
  168. package/universal/types/_common/Uint8Array.ts +77 -0
  169. package/universal/types/_common/accountAccessKey.ts +41 -3
  170. package/universal/types/_common/common.ts +5 -17
  171. package/universal/types/_common/keyPair/keyPair.ts +8 -7
  172. package/universal/types/_common/keyPair/randomEd25519KeyPair.ts +7 -5
  173. package/universal/types/_common/keyPair/randomSecp256k1KeyPair.ts +7 -5
  174. package/universal/types/_common/message.ts +74 -0
  175. package/universal/types/{natError.ts → _common/natError.ts} +18 -16
  176. package/universal/types/_common/nearGas.ts +2 -4
  177. package/universal/types/_common/nearToken.ts +7 -19
  178. package/universal/types/_common/transaction/actions/actions.ts +18 -0
  179. package/universal/types/{actions → _common/transaction/actions}/addKey.ts +11 -11
  180. package/universal/types/{actions → _common/transaction/actions}/deleteAccount.ts +3 -3
  181. package/universal/types/{actions → _common/transaction/actions}/deleteKey.ts +5 -7
  182. package/universal/types/{actions → _common/transaction/actions}/deployContract.ts +3 -3
  183. package/universal/types/{actions → _common/transaction/actions}/functionCall.ts +16 -24
  184. package/universal/types/_common/transaction/actions/sponsor.ts +77 -0
  185. package/universal/types/{actions → _common/transaction/actions}/stake.ts +5 -6
  186. package/universal/types/{actions → _common/transaction/actions}/transfer.ts +5 -7
  187. package/universal/types/_common/transaction/delegation.ts +52 -0
  188. package/universal/types/_common/transaction/rpcTransactionErrorContext.ts +1 -1
  189. package/universal/types/_common/transaction/transaction.ts +24 -19
  190. package/universal/types/_common/verifySignature.ts +27 -0
  191. package/universal/types/client/cache/getRecentBlockHash.ts +7 -5
  192. package/universal/types/client/client.ts +31 -8
  193. package/universal/types/client/createClient.ts +2 -4
  194. package/universal/types/client/methods/_common/common.ts +1 -1
  195. package/universal/types/client/methods/account/getAccountAccessKey.ts +22 -6
  196. package/universal/types/client/methods/account/getAccountAccessKeys.ts +22 -6
  197. package/universal/types/client/methods/account/getAccountInfo.ts +25 -12
  198. package/universal/types/client/methods/block/getBlock.ts +9 -6
  199. package/universal/types/client/methods/contract/callContractReadFunction.ts +69 -56
  200. package/universal/types/client/methods/contract/getContractState.ts +9 -7
  201. package/universal/types/client/methods/protocol/getGasPrice.ts +1 -3
  202. package/universal/types/client/methods/protocol/getProtocolConfig.ts +3 -7
  203. package/universal/types/client/methods/transaction/sendSignedTransaction.ts +9 -4
  204. package/universal/types/client/transport/sendRequest.ts +13 -9
  205. package/universal/types/keyServices/memoryKeyService/createFindKeyPair.ts +1 -3
  206. package/universal/types/keyServices/memoryKeyService/createMemoryKeyService.ts +1 -3
  207. package/universal/types/keyServices/memoryKeyService/createSignTransaction.ts +1 -3
  208. package/universal/types/keyServices/memoryKeyService/memoryKeyService.ts +1 -1
  209. package/universal/types/signers/memorySigner/_common/errorContext.ts +6 -6
  210. package/universal/types/signers/memorySigner/inner/keyPool.ts +3 -5
  211. package/universal/types/signers/memorySigner/inner/taskQueue.ts +18 -8
  212. package/universal/types/signers/memorySigner/inner/tasker.ts +2 -7
  213. package/universal/types/signers/memorySigner/memorySigner.ts +11 -3
  214. package/universal/types/signers/memorySigner/public/createExecuteTransaction.ts +11 -8
  215. package/universal/types/signers/memorySigner/public/createMemorySigner.ts +2 -2
  216. package/universal/types/signers/memorySigner/public/createSignTransaction.ts +9 -10
  217. package/universal/src/_common/schemas/borsh/actions/signedDelegate.ts +0 -13
  218. package/universal/src/_common/schemas/borsh/index.ts +0 -2
  219. package/universal/types/actions/actions.ts +0 -16
  220. /package/universal/types/{actions → _common/transaction/actions}/createAccount.ts +0 -0
package/README.md CHANGED
@@ -10,7 +10,7 @@ TypeScript library for interactions with Near Protocol in the browser or Node.js
10
10
  pnpm add near-api-ts
11
11
  ```
12
12
 
13
- **Node.js (esm, 24+) / Browser**
13
+ **Node.js (esm, 25+) / Browser**
14
14
 
15
15
  ```ts
16
16
  import {
@@ -1,10 +1,11 @@
1
1
  // import * as z from 'zod/mini';
2
- import { asThrowable } from '@universal/src/_common/utils/asThrowable';
3
- import { result } from '@universal/src/_common/utils/result';
4
- import { wrapInternalError } from '@universal/src/_common/utils/wrapInternalError';
5
- import type { Result } from '@universal/types/_common/common';
6
- import type { PublicKey } from '@universal/types/_common/crypto';
7
- import type { KeyPair } from '@universal/types/_common/keyPair/keyPair';
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 '@universal/index';
2
- import { result } from '@universal/src/_common/utils/result';
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 '@universal/index';
2
- import { result } from '@universal/src/_common/utils/result';
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: IdbKeyServiceContext) => async (args: any) => {
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
- const kp = keyPair(args.privateKey);
8
+ const kp = keyPair(args.privateKey);
10
9
 
11
- // 2. Put the private key to the Idb
12
- const request = context.idb
13
- .transaction(['keyPairs'], 'readwrite')
14
- .objectStore('keyPairs')
15
- .put(kp.privateKey, kp.publicKey);
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
- await new Promise((resolve, reject) => {
18
- request.onsuccess = () => {
19
- console.log('Key added', request.result);
20
- context.keyPairs.set(kp.publicKey, kp);
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
- resolve(result.ok(request.result));
23
- };
21
+ resolve(result.ok(request.result));
22
+ };
24
23
 
25
- request.onerror = () => {
26
- console.log('Error while adding key', request.error);
27
- reject(request.error);
28
- };
29
- });
24
+ request.onerror = () => {
25
+ console.log('Error while adding key', request.error);
26
+ reject(request.error);
27
+ };
28
+ });
30
29
 
31
- return result.ok(kp);
32
- };
30
+ return result.ok(kp);
31
+ };
@@ -1,4 +1,4 @@
1
- import { result } from '@universal/src/_common/utils/result';
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 '@universal/src/_common/utils/result';
1
+ import { result } from '../../../../universal/src/_common/utils/result';
2
2
  import type { IdbKeyServiceContext } from '../idbKeyService';
3
3
 
4
- export const createSafeHasKey =
5
- (context: IdbKeyServiceContext) => async (args: any) => {
6
- const keyPair = await context.getKeyPair(args.publicKey);
7
- /// TODO rework
8
- return result.ok(keyPair.ok);
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,4 +1,4 @@
1
- import { result } from '@universal/src/_common/utils/result';
1
+ import { result } from '../../../../universal/src/_common/utils/result';
2
2
  import type { IdbKeyServiceContext } from '../idbKeyService';
3
3
 
4
4
  export const createSafeRemoveKey =
@@ -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
- `IdbKeyService.SignTransaction.Internal`,
16
- async (args: any) => {
17
- const validArgs = SignTransactionArgsSchema.safeParse(args);
18
-
19
- if (!validArgs.success)
20
- return result.err(
21
- createNatError({
22
- kind: `IdbKeyService.SignTransaction.Args.InvalidSchema`,
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
- // TODO Think if it's possible to wrap into some helper function
34
- if (!keyPair.ok) {
35
- // if (keyPair.error.kind === 'MemoryKeyService.FindKeyPair.NotFound')
36
- // return result.err(
37
- // createNatError({
38
- // kind: 'MemoryKeyService.SignTransaction.SigningKeyPair.NotFound',
39
- // context: {
40
- // signerPublicKey: innerTransaction.signerPublicKey.publicKey,
41
- // },
42
- // }),
43
- // );
44
- console.log(keyPair);
45
- throw keyPair.error;
46
- }
47
-
48
- const { transactionHash, u8TransactionHash } =
49
- getTransactionHash(innerTransaction);
50
-
51
- const { signature } = keyPair.value.sign(u8TransactionHash); // todo make async?
52
-
53
- return result.ok({
54
- transaction: args.transaction,
55
- transactionHash,
56
- signature,
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 { InternalErrorContext, InvalidSchemaErrorContext } from '@universal/types/natError';
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 '@universal/types/natError' {
3
+ declare module '../../universal/types/_common/natError' {
4
4
  interface NatPublicErrorRegistry extends IdbKeyServicePublicErrorRegister {}
5
5
  }