@mysten/sui 0.0.0-experimental-20240529040124

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 (609) hide show
  1. package/CHANGELOG.md +905 -0
  2. package/LICENSE +201 -0
  3. package/README.md +520 -0
  4. package/bcs/package.json +6 -0
  5. package/client/package.json +6 -0
  6. package/cryptography/package.json +6 -0
  7. package/dist/cjs/bcs/bcs.d.ts +2283 -0
  8. package/dist/cjs/bcs/bcs.js +306 -0
  9. package/dist/cjs/bcs/bcs.js.map +7 -0
  10. package/dist/cjs/bcs/effects.d.ts +793 -0
  11. package/dist/cjs/bcs/effects.js +203 -0
  12. package/dist/cjs/bcs/effects.js.map +7 -0
  13. package/dist/cjs/bcs/index.d.ts +3081 -0
  14. package/dist/cjs/bcs/index.js +73 -0
  15. package/dist/cjs/bcs/index.js.map +7 -0
  16. package/dist/cjs/bcs/type-tag-serializer.d.ts +6 -0
  17. package/dist/cjs/bcs/type-tag-serializer.js +113 -0
  18. package/dist/cjs/bcs/type-tag-serializer.js.map +7 -0
  19. package/dist/cjs/bcs/types.d.ts +114 -0
  20. package/dist/cjs/bcs/types.js +27 -0
  21. package/dist/cjs/bcs/types.js.map +7 -0
  22. package/dist/cjs/client/client.d.ts +229 -0
  23. package/dist/cjs/client/client.js +582 -0
  24. package/dist/cjs/client/client.js.map +7 -0
  25. package/dist/cjs/client/errors.d.ts +12 -0
  26. package/dist/cjs/client/errors.js +60 -0
  27. package/dist/cjs/client/errors.js.map +7 -0
  28. package/dist/cjs/client/http-transport.d.ts +40 -0
  29. package/dist/cjs/client/http-transport.js +125 -0
  30. package/dist/cjs/client/http-transport.js.map +7 -0
  31. package/dist/cjs/client/index.d.ts +5 -0
  32. package/dist/cjs/client/index.js +36 -0
  33. package/dist/cjs/client/index.js.map +7 -0
  34. package/dist/cjs/client/network.d.ts +1 -0
  35. package/dist/cjs/client/network.js +38 -0
  36. package/dist/cjs/client/network.js.map +7 -0
  37. package/dist/cjs/client/rpc-websocket-client.d.ts +49 -0
  38. package/dist/cjs/client/rpc-websocket-client.js +206 -0
  39. package/dist/cjs/client/rpc-websocket-client.js.map +7 -0
  40. package/dist/cjs/client/types/chain.d.ts +99 -0
  41. package/dist/cjs/client/types/chain.js +17 -0
  42. package/dist/cjs/client/types/chain.js.map +7 -0
  43. package/dist/cjs/client/types/changes.d.ts +19 -0
  44. package/dist/cjs/client/types/changes.js +17 -0
  45. package/dist/cjs/client/types/changes.js.map +7 -0
  46. package/dist/cjs/client/types/coins.d.ts +6 -0
  47. package/dist/cjs/client/types/coins.js +17 -0
  48. package/dist/cjs/client/types/coins.js.map +7 -0
  49. package/dist/cjs/client/types/common.d.ts +2 -0
  50. package/dist/cjs/client/types/common.js +17 -0
  51. package/dist/cjs/client/types/common.js.map +7 -0
  52. package/dist/cjs/client/types/generated.d.ts +1376 -0
  53. package/dist/cjs/client/types/generated.js +17 -0
  54. package/dist/cjs/client/types/generated.js.map +7 -0
  55. package/dist/cjs/client/types/index.d.ts +6 -0
  56. package/dist/cjs/client/types/index.js +24 -0
  57. package/dist/cjs/client/types/index.js.map +7 -0
  58. package/dist/cjs/client/types/params.d.ts +585 -0
  59. package/dist/cjs/client/types/params.js +17 -0
  60. package/dist/cjs/client/types/params.js.map +7 -0
  61. package/dist/cjs/cryptography/index.d.ts +7 -0
  62. package/dist/cjs/cryptography/index.js +47 -0
  63. package/dist/cjs/cryptography/index.js.map +7 -0
  64. package/dist/cjs/cryptography/intent.d.ts +6 -0
  65. package/dist/cjs/cryptography/intent.js +35 -0
  66. package/dist/cjs/cryptography/intent.js.map +7 -0
  67. package/dist/cjs/cryptography/keypair.d.ts +63 -0
  68. package/dist/cjs/cryptography/keypair.js +105 -0
  69. package/dist/cjs/cryptography/keypair.js.map +7 -0
  70. package/dist/cjs/cryptography/mnemonics.d.ts +27 -0
  71. package/dist/cjs/cryptography/mnemonics.js +47 -0
  72. package/dist/cjs/cryptography/mnemonics.js.map +7 -0
  73. package/dist/cjs/cryptography/publickey.d.ts +56 -0
  74. package/dist/cjs/cryptography/publickey.js +112 -0
  75. package/dist/cjs/cryptography/publickey.js.map +7 -0
  76. package/dist/cjs/cryptography/signature-scheme.d.ts +21 -0
  77. package/dist/cjs/cryptography/signature-scheme.js +45 -0
  78. package/dist/cjs/cryptography/signature-scheme.js.map +7 -0
  79. package/dist/cjs/cryptography/signature.d.ts +60 -0
  80. package/dist/cjs/cryptography/signature.js +75 -0
  81. package/dist/cjs/cryptography/signature.js.map +7 -0
  82. package/dist/cjs/faucet/faucet.d.ts +42 -0
  83. package/dist/cjs/faucet/faucet.js +103 -0
  84. package/dist/cjs/faucet/faucet.js.map +7 -0
  85. package/dist/cjs/faucet/index.d.ts +1 -0
  86. package/dist/cjs/faucet/index.js +29 -0
  87. package/dist/cjs/faucet/index.js.map +7 -0
  88. package/dist/cjs/graphql/client.d.ts +42 -0
  89. package/dist/cjs/graphql/client.js +93 -0
  90. package/dist/cjs/graphql/client.js.map +7 -0
  91. package/dist/cjs/graphql/generated/2024-01/tada-env.d.js +17 -0
  92. package/dist/cjs/graphql/generated/2024-01/tada-env.d.js.map +7 -0
  93. package/dist/cjs/graphql/generated/2024.1/tada-env.d.js +17 -0
  94. package/dist/cjs/graphql/generated/2024.1/tada-env.d.js.map +7 -0
  95. package/dist/cjs/graphql/generated/2024.1/tsconfig.tada.js +12 -0
  96. package/dist/cjs/graphql/generated/2024.1/tsconfig.tada.js.map +7 -0
  97. package/dist/cjs/graphql/generated/2024.4/tada-env.d.js +17 -0
  98. package/dist/cjs/graphql/generated/2024.4/tada-env.d.js.map +7 -0
  99. package/dist/cjs/graphql/generated/2024.4/tsconfig.tada.js +12 -0
  100. package/dist/cjs/graphql/generated/2024.4/tsconfig.tada.js.map +7 -0
  101. package/dist/cjs/graphql/index.d.ts +1 -0
  102. package/dist/cjs/graphql/index.js +26 -0
  103. package/dist/cjs/graphql/index.js.map +7 -0
  104. package/dist/cjs/graphql/schemas/2024.1/index.d.ts +8971 -0
  105. package/dist/cjs/graphql/schemas/2024.1/index.js +31 -0
  106. package/dist/cjs/graphql/schemas/2024.1/index.js.map +7 -0
  107. package/dist/cjs/graphql/schemas/2024.4/index.d.ts +8995 -0
  108. package/dist/cjs/graphql/schemas/2024.4/index.js +31 -0
  109. package/dist/cjs/graphql/schemas/2024.4/index.js.map +7 -0
  110. package/dist/cjs/graphql/types.d.ts +70 -0
  111. package/dist/cjs/graphql/types.js +17 -0
  112. package/dist/cjs/graphql/types.js.map +7 -0
  113. package/dist/cjs/keypairs/ed25519/ed25519-hd-key.d.ts +13 -0
  114. package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js +101 -0
  115. package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js.map +7 -0
  116. package/dist/cjs/keypairs/ed25519/index.d.ts +2 -0
  117. package/dist/cjs/keypairs/ed25519/index.js +28 -0
  118. package/dist/cjs/keypairs/ed25519/index.js.map +7 -0
  119. package/dist/cjs/keypairs/ed25519/keypair.d.ts +74 -0
  120. package/dist/cjs/keypairs/ed25519/keypair.js +151 -0
  121. package/dist/cjs/keypairs/ed25519/keypair.js.map +7 -0
  122. package/dist/cjs/keypairs/ed25519/publickey.d.ts +30 -0
  123. package/dist/cjs/keypairs/ed25519/publickey.js +99 -0
  124. package/dist/cjs/keypairs/ed25519/publickey.js.map +7 -0
  125. package/dist/cjs/keypairs/secp256k1/index.d.ts +2 -0
  126. package/dist/cjs/keypairs/secp256k1/index.js +28 -0
  127. package/dist/cjs/keypairs/secp256k1/index.js.map +7 -0
  128. package/dist/cjs/keypairs/secp256k1/keypair.d.ts +73 -0
  129. package/dist/cjs/keypairs/secp256k1/keypair.js +143 -0
  130. package/dist/cjs/keypairs/secp256k1/keypair.js.map +7 -0
  131. package/dist/cjs/keypairs/secp256k1/publickey.d.ts +30 -0
  132. package/dist/cjs/keypairs/secp256k1/publickey.js +94 -0
  133. package/dist/cjs/keypairs/secp256k1/publickey.js.map +7 -0
  134. package/dist/cjs/keypairs/secp256r1/index.d.ts +2 -0
  135. package/dist/cjs/keypairs/secp256r1/index.js +28 -0
  136. package/dist/cjs/keypairs/secp256r1/index.js.map +7 -0
  137. package/dist/cjs/keypairs/secp256r1/keypair.d.ts +73 -0
  138. package/dist/cjs/keypairs/secp256r1/keypair.js +137 -0
  139. package/dist/cjs/keypairs/secp256r1/keypair.js.map +7 -0
  140. package/dist/cjs/keypairs/secp256r1/publickey.d.ts +30 -0
  141. package/dist/cjs/keypairs/secp256r1/publickey.js +94 -0
  142. package/dist/cjs/keypairs/secp256r1/publickey.js.map +7 -0
  143. package/dist/cjs/multisig/index.d.ts +2 -0
  144. package/dist/cjs/multisig/index.js +28 -0
  145. package/dist/cjs/multisig/index.js.map +7 -0
  146. package/dist/cjs/multisig/publickey.d.ts +110 -0
  147. package/dist/cjs/multisig/publickey.js +260 -0
  148. package/dist/cjs/multisig/publickey.js.map +7 -0
  149. package/dist/cjs/multisig/signer.d.ts +19 -0
  150. package/dist/cjs/multisig/signer.js +115 -0
  151. package/dist/cjs/multisig/signer.js.map +7 -0
  152. package/dist/cjs/package.json +5 -0
  153. package/dist/cjs/transactions/Commands.d.ts +110 -0
  154. package/dist/cjs/transactions/Commands.js +140 -0
  155. package/dist/cjs/transactions/Commands.js.map +7 -0
  156. package/dist/cjs/transactions/Inputs.d.ts +22 -0
  157. package/dist/cjs/transactions/Inputs.js +80 -0
  158. package/dist/cjs/transactions/Inputs.js.map +7 -0
  159. package/dist/cjs/transactions/ObjectCache.d.ts +85 -0
  160. package/dist/cjs/transactions/ObjectCache.js +246 -0
  161. package/dist/cjs/transactions/ObjectCache.js.map +7 -0
  162. package/dist/cjs/transactions/Transaction.d.ts +672 -0
  163. package/dist/cjs/transactions/Transaction.js +459 -0
  164. package/dist/cjs/transactions/Transaction.js.map +7 -0
  165. package/dist/cjs/transactions/TransactionData.d.ts +64 -0
  166. package/dist/cjs/transactions/TransactionData.js +249 -0
  167. package/dist/cjs/transactions/TransactionData.js.map +7 -0
  168. package/dist/cjs/transactions/__tests__/Transaction.test.d.ts +1 -0
  169. package/dist/cjs/transactions/__tests__/bcs.test.d.ts +1 -0
  170. package/dist/cjs/transactions/data/internal.d.ts +2689 -0
  171. package/dist/cjs/transactions/data/internal.js +210 -0
  172. package/dist/cjs/transactions/data/internal.js.map +7 -0
  173. package/dist/cjs/transactions/data/v1.d.ts +1839 -0
  174. package/dist/cjs/transactions/data/v1.js +440 -0
  175. package/dist/cjs/transactions/data/v1.js.map +7 -0
  176. package/dist/cjs/transactions/data/v2.d.ts +450 -0
  177. package/dist/cjs/transactions/data/v2.js +123 -0
  178. package/dist/cjs/transactions/data/v2.js.map +7 -0
  179. package/dist/cjs/transactions/executor/caching.d.ts +29 -0
  180. package/dist/cjs/transactions/executor/caching.js +109 -0
  181. package/dist/cjs/transactions/executor/caching.js.map +7 -0
  182. package/dist/cjs/transactions/executor/parallel.d.ts +22 -0
  183. package/dist/cjs/transactions/executor/parallel.js +316 -0
  184. package/dist/cjs/transactions/executor/parallel.js.map +7 -0
  185. package/dist/cjs/transactions/executor/queue.d.ts +11 -0
  186. package/dist/cjs/transactions/executor/queue.js +92 -0
  187. package/dist/cjs/transactions/executor/queue.js.map +7 -0
  188. package/dist/cjs/transactions/executor/serial.d.ts +27 -0
  189. package/dist/cjs/transactions/executor/serial.js +140 -0
  190. package/dist/cjs/transactions/executor/serial.js.map +7 -0
  191. package/dist/cjs/transactions/hash.d.ts +7 -0
  192. package/dist/cjs/transactions/hash.js +32 -0
  193. package/dist/cjs/transactions/hash.js.map +7 -0
  194. package/dist/cjs/transactions/index.d.ts +13 -0
  195. package/dist/cjs/transactions/index.js +47 -0
  196. package/dist/cjs/transactions/index.js.map +7 -0
  197. package/dist/cjs/transactions/intents/CoinWithBalance.d.ts +6 -0
  198. package/dist/cjs/transactions/intents/CoinWithBalance.js +168 -0
  199. package/dist/cjs/transactions/intents/CoinWithBalance.js.map +7 -0
  200. package/dist/cjs/transactions/json-rpc-resolver.d.ts +12 -0
  201. package/dist/cjs/transactions/json-rpc-resolver.js +353 -0
  202. package/dist/cjs/transactions/json-rpc-resolver.js.map +7 -0
  203. package/dist/cjs/transactions/pure.d.ts +185 -0
  204. package/dist/cjs/transactions/pure.js +41 -0
  205. package/dist/cjs/transactions/pure.js.map +7 -0
  206. package/dist/cjs/transactions/serializer.d.ts +7 -0
  207. package/dist/cjs/transactions/serializer.js +176 -0
  208. package/dist/cjs/transactions/serializer.js.map +7 -0
  209. package/dist/cjs/transactions/utils.d.ts +8 -0
  210. package/dist/cjs/transactions/utils.js +66 -0
  211. package/dist/cjs/transactions/utils.js.map +7 -0
  212. package/dist/cjs/utils/constants.d.ts +9 -0
  213. package/dist/cjs/utils/constants.js +42 -0
  214. package/dist/cjs/utils/constants.js.map +7 -0
  215. package/dist/cjs/utils/format.d.ts +2 -0
  216. package/dist/cjs/utils/format.js +36 -0
  217. package/dist/cjs/utils/format.js.map +7 -0
  218. package/dist/cjs/utils/index.d.ts +5 -0
  219. package/dist/cjs/utils/index.js +53 -0
  220. package/dist/cjs/utils/index.js.map +7 -0
  221. package/dist/cjs/utils/sui-types.d.ts +27 -0
  222. package/dist/cjs/utils/sui-types.js +90 -0
  223. package/dist/cjs/utils/sui-types.js.map +7 -0
  224. package/dist/cjs/utils/suins.d.ts +2 -0
  225. package/dist/cjs/utils/suins.js +57 -0
  226. package/dist/cjs/utils/suins.js.map +7 -0
  227. package/dist/cjs/verify/index.d.ts +1 -0
  228. package/dist/cjs/verify/index.js +29 -0
  229. package/dist/cjs/verify/index.js.map +7 -0
  230. package/dist/cjs/verify/verify.d.ts +11 -0
  231. package/dist/cjs/verify/verify.js +101 -0
  232. package/dist/cjs/verify/verify.js.map +7 -0
  233. package/dist/cjs/version.d.ts +2 -0
  234. package/dist/cjs/version.js +27 -0
  235. package/dist/cjs/version.js.map +7 -0
  236. package/dist/cjs/zklogin/address.d.ts +1 -0
  237. package/dist/cjs/zklogin/address.js +44 -0
  238. package/dist/cjs/zklogin/address.js.map +7 -0
  239. package/dist/cjs/zklogin/bcs.d.ts +46 -0
  240. package/dist/cjs/zklogin/bcs.js +42 -0
  241. package/dist/cjs/zklogin/bcs.js.map +7 -0
  242. package/dist/cjs/zklogin/index.d.ts +5 -0
  243. package/dist/cjs/zklogin/index.js +33 -0
  244. package/dist/cjs/zklogin/index.js.map +7 -0
  245. package/dist/cjs/zklogin/jwt-utils.d.ts +5 -0
  246. package/dist/cjs/zklogin/jwt-utils.js +102 -0
  247. package/dist/cjs/zklogin/jwt-utils.js.map +7 -0
  248. package/dist/cjs/zklogin/publickey.d.ts +69 -0
  249. package/dist/cjs/zklogin/publickey.js +197 -0
  250. package/dist/cjs/zklogin/publickey.js.map +7 -0
  251. package/dist/cjs/zklogin/signature.d.ts +23 -0
  252. package/dist/cjs/zklogin/signature.js +48 -0
  253. package/dist/cjs/zklogin/signature.js.map +7 -0
  254. package/dist/cjs/zklogin/utils.d.ts +2 -0
  255. package/dist/cjs/zklogin/utils.js +46 -0
  256. package/dist/cjs/zklogin/utils.js.map +7 -0
  257. package/dist/esm/bcs/bcs.d.ts +2283 -0
  258. package/dist/esm/bcs/bcs.js +286 -0
  259. package/dist/esm/bcs/bcs.js.map +7 -0
  260. package/dist/esm/bcs/effects.d.ts +793 -0
  261. package/dist/esm/bcs/effects.js +183 -0
  262. package/dist/esm/bcs/effects.js.map +7 -0
  263. package/dist/esm/bcs/index.d.ts +3081 -0
  264. package/dist/esm/bcs/index.js +83 -0
  265. package/dist/esm/bcs/index.js.map +7 -0
  266. package/dist/esm/bcs/type-tag-serializer.d.ts +6 -0
  267. package/dist/esm/bcs/type-tag-serializer.js +93 -0
  268. package/dist/esm/bcs/type-tag-serializer.js.map +7 -0
  269. package/dist/esm/bcs/types.d.ts +114 -0
  270. package/dist/esm/bcs/types.js +7 -0
  271. package/dist/esm/bcs/types.js.map +7 -0
  272. package/dist/esm/client/client.d.ts +229 -0
  273. package/dist/esm/client/client.js +568 -0
  274. package/dist/esm/client/client.js.map +7 -0
  275. package/dist/esm/client/errors.d.ts +12 -0
  276. package/dist/esm/client/errors.js +40 -0
  277. package/dist/esm/client/errors.js.map +7 -0
  278. package/dist/esm/client/http-transport.d.ts +40 -0
  279. package/dist/esm/client/http-transport.js +105 -0
  280. package/dist/esm/client/http-transport.js.map +7 -0
  281. package/dist/esm/client/index.d.ts +5 -0
  282. package/dist/esm/client/index.js +20 -0
  283. package/dist/esm/client/index.js.map +7 -0
  284. package/dist/esm/client/network.d.ts +1 -0
  285. package/dist/esm/client/network.js +18 -0
  286. package/dist/esm/client/network.js.map +7 -0
  287. package/dist/esm/client/rpc-websocket-client.d.ts +49 -0
  288. package/dist/esm/client/rpc-websocket-client.js +186 -0
  289. package/dist/esm/client/rpc-websocket-client.js.map +7 -0
  290. package/dist/esm/client/types/chain.d.ts +99 -0
  291. package/dist/esm/client/types/chain.js +1 -0
  292. package/dist/esm/client/types/chain.js.map +7 -0
  293. package/dist/esm/client/types/changes.d.ts +19 -0
  294. package/dist/esm/client/types/changes.js +1 -0
  295. package/dist/esm/client/types/changes.js.map +7 -0
  296. package/dist/esm/client/types/coins.d.ts +6 -0
  297. package/dist/esm/client/types/coins.js +1 -0
  298. package/dist/esm/client/types/coins.js.map +7 -0
  299. package/dist/esm/client/types/common.d.ts +2 -0
  300. package/dist/esm/client/types/common.js +1 -0
  301. package/dist/esm/client/types/common.js.map +7 -0
  302. package/dist/esm/client/types/generated.d.ts +1376 -0
  303. package/dist/esm/client/types/generated.js +1 -0
  304. package/dist/esm/client/types/generated.js.map +7 -0
  305. package/dist/esm/client/types/index.d.ts +6 -0
  306. package/dist/esm/client/types/index.js +7 -0
  307. package/dist/esm/client/types/index.js.map +7 -0
  308. package/dist/esm/client/types/params.d.ts +585 -0
  309. package/dist/esm/client/types/params.js +1 -0
  310. package/dist/esm/client/types/params.js.map +7 -0
  311. package/dist/esm/cryptography/index.d.ts +7 -0
  312. package/dist/esm/cryptography/index.js +47 -0
  313. package/dist/esm/cryptography/index.js.map +7 -0
  314. package/dist/esm/cryptography/intent.d.ts +6 -0
  315. package/dist/esm/cryptography/intent.js +15 -0
  316. package/dist/esm/cryptography/intent.js.map +7 -0
  317. package/dist/esm/cryptography/keypair.d.ts +63 -0
  318. package/dist/esm/cryptography/keypair.js +85 -0
  319. package/dist/esm/cryptography/keypair.js.map +7 -0
  320. package/dist/esm/cryptography/mnemonics.d.ts +27 -0
  321. package/dist/esm/cryptography/mnemonics.js +27 -0
  322. package/dist/esm/cryptography/mnemonics.js.map +7 -0
  323. package/dist/esm/cryptography/publickey.d.ts +56 -0
  324. package/dist/esm/cryptography/publickey.js +92 -0
  325. package/dist/esm/cryptography/publickey.js.map +7 -0
  326. package/dist/esm/cryptography/signature-scheme.d.ts +21 -0
  327. package/dist/esm/cryptography/signature-scheme.js +25 -0
  328. package/dist/esm/cryptography/signature-scheme.js.map +7 -0
  329. package/dist/esm/cryptography/signature.d.ts +60 -0
  330. package/dist/esm/cryptography/signature.js +59 -0
  331. package/dist/esm/cryptography/signature.js.map +7 -0
  332. package/dist/esm/faucet/faucet.d.ts +42 -0
  333. package/dist/esm/faucet/faucet.js +83 -0
  334. package/dist/esm/faucet/faucet.js.map +7 -0
  335. package/dist/esm/faucet/index.d.ts +1 -0
  336. package/dist/esm/faucet/index.js +15 -0
  337. package/dist/esm/faucet/index.js.map +7 -0
  338. package/dist/esm/graphql/client.d.ts +42 -0
  339. package/dist/esm/graphql/client.js +73 -0
  340. package/dist/esm/graphql/client.js.map +7 -0
  341. package/dist/esm/graphql/generated/2024-01/tada-env.d.js +1 -0
  342. package/dist/esm/graphql/generated/2024-01/tada-env.d.js.map +7 -0
  343. package/dist/esm/graphql/generated/2024.1/tada-env.d.js +1 -0
  344. package/dist/esm/graphql/generated/2024.1/tada-env.d.js.map +7 -0
  345. package/dist/esm/graphql/generated/2024.1/tsconfig.tada.js +17 -0
  346. package/dist/esm/graphql/generated/2024.1/tsconfig.tada.js.map +7 -0
  347. package/dist/esm/graphql/generated/2024.4/tada-env.d.js +1 -0
  348. package/dist/esm/graphql/generated/2024.4/tada-env.d.js.map +7 -0
  349. package/dist/esm/graphql/generated/2024.4/tsconfig.tada.js +17 -0
  350. package/dist/esm/graphql/generated/2024.4/tsconfig.tada.js.map +7 -0
  351. package/dist/esm/graphql/index.d.ts +1 -0
  352. package/dist/esm/graphql/index.js +9 -0
  353. package/dist/esm/graphql/index.js.map +7 -0
  354. package/dist/esm/graphql/schemas/2024.1/index.d.ts +8971 -0
  355. package/dist/esm/graphql/schemas/2024.1/index.js +10 -0
  356. package/dist/esm/graphql/schemas/2024.1/index.js.map +7 -0
  357. package/dist/esm/graphql/schemas/2024.4/index.d.ts +8995 -0
  358. package/dist/esm/graphql/schemas/2024.4/index.js +10 -0
  359. package/dist/esm/graphql/schemas/2024.4/index.js.map +7 -0
  360. package/dist/esm/graphql/types.d.ts +70 -0
  361. package/dist/esm/graphql/types.js +1 -0
  362. package/dist/esm/graphql/types.js.map +7 -0
  363. package/dist/esm/keypairs/ed25519/ed25519-hd-key.d.ts +13 -0
  364. package/dist/esm/keypairs/ed25519/ed25519-hd-key.js +71 -0
  365. package/dist/esm/keypairs/ed25519/ed25519-hd-key.js.map +7 -0
  366. package/dist/esm/keypairs/ed25519/index.d.ts +2 -0
  367. package/dist/esm/keypairs/ed25519/index.js +11 -0
  368. package/dist/esm/keypairs/ed25519/index.js.map +7 -0
  369. package/dist/esm/keypairs/ed25519/keypair.d.ts +74 -0
  370. package/dist/esm/keypairs/ed25519/keypair.js +121 -0
  371. package/dist/esm/keypairs/ed25519/keypair.js.map +7 -0
  372. package/dist/esm/keypairs/ed25519/publickey.d.ts +30 -0
  373. package/dist/esm/keypairs/ed25519/publickey.js +69 -0
  374. package/dist/esm/keypairs/ed25519/publickey.js.map +7 -0
  375. package/dist/esm/keypairs/secp256k1/index.d.ts +2 -0
  376. package/dist/esm/keypairs/secp256k1/index.js +11 -0
  377. package/dist/esm/keypairs/secp256k1/index.js.map +7 -0
  378. package/dist/esm/keypairs/secp256k1/keypair.d.ts +73 -0
  379. package/dist/esm/keypairs/secp256k1/keypair.js +123 -0
  380. package/dist/esm/keypairs/secp256k1/keypair.js.map +7 -0
  381. package/dist/esm/keypairs/secp256k1/publickey.d.ts +30 -0
  382. package/dist/esm/keypairs/secp256k1/publickey.js +74 -0
  383. package/dist/esm/keypairs/secp256k1/publickey.js.map +7 -0
  384. package/dist/esm/keypairs/secp256r1/index.d.ts +2 -0
  385. package/dist/esm/keypairs/secp256r1/index.js +11 -0
  386. package/dist/esm/keypairs/secp256r1/index.js.map +7 -0
  387. package/dist/esm/keypairs/secp256r1/keypair.d.ts +73 -0
  388. package/dist/esm/keypairs/secp256r1/keypair.js +117 -0
  389. package/dist/esm/keypairs/secp256r1/keypair.js.map +7 -0
  390. package/dist/esm/keypairs/secp256r1/publickey.d.ts +30 -0
  391. package/dist/esm/keypairs/secp256r1/publickey.js +74 -0
  392. package/dist/esm/keypairs/secp256r1/publickey.js.map +7 -0
  393. package/dist/esm/multisig/index.d.ts +2 -0
  394. package/dist/esm/multisig/index.js +8 -0
  395. package/dist/esm/multisig/index.js.map +7 -0
  396. package/dist/esm/multisig/publickey.d.ts +110 -0
  397. package/dist/esm/multisig/publickey.js +243 -0
  398. package/dist/esm/multisig/publickey.js.map +7 -0
  399. package/dist/esm/multisig/signer.d.ts +19 -0
  400. package/dist/esm/multisig/signer.js +95 -0
  401. package/dist/esm/multisig/signer.js.map +7 -0
  402. package/dist/esm/package.json +5 -0
  403. package/dist/esm/transactions/Commands.d.ts +110 -0
  404. package/dist/esm/transactions/Commands.js +120 -0
  405. package/dist/esm/transactions/Commands.js.map +7 -0
  406. package/dist/esm/transactions/Inputs.d.ts +22 -0
  407. package/dist/esm/transactions/Inputs.js +60 -0
  408. package/dist/esm/transactions/Inputs.js.map +7 -0
  409. package/dist/esm/transactions/ObjectCache.d.ts +85 -0
  410. package/dist/esm/transactions/ObjectCache.js +226 -0
  411. package/dist/esm/transactions/ObjectCache.js.map +7 -0
  412. package/dist/esm/transactions/Transaction.d.ts +672 -0
  413. package/dist/esm/transactions/Transaction.js +439 -0
  414. package/dist/esm/transactions/Transaction.js.map +7 -0
  415. package/dist/esm/transactions/TransactionData.d.ts +64 -0
  416. package/dist/esm/transactions/TransactionData.js +229 -0
  417. package/dist/esm/transactions/TransactionData.js.map +7 -0
  418. package/dist/esm/transactions/__tests__/Transaction.test.d.ts +1 -0
  419. package/dist/esm/transactions/__tests__/bcs.test.d.ts +1 -0
  420. package/dist/esm/transactions/data/internal.d.ts +2689 -0
  421. package/dist/esm/transactions/data/internal.js +208 -0
  422. package/dist/esm/transactions/data/internal.js.map +7 -0
  423. package/dist/esm/transactions/data/v1.d.ts +1839 -0
  424. package/dist/esm/transactions/data/v1.js +437 -0
  425. package/dist/esm/transactions/data/v1.js.map +7 -0
  426. package/dist/esm/transactions/data/v2.d.ts +450 -0
  427. package/dist/esm/transactions/data/v2.js +118 -0
  428. package/dist/esm/transactions/data/v2.js.map +7 -0
  429. package/dist/esm/transactions/executor/caching.d.ts +29 -0
  430. package/dist/esm/transactions/executor/caching.js +89 -0
  431. package/dist/esm/transactions/executor/caching.js.map +7 -0
  432. package/dist/esm/transactions/executor/parallel.d.ts +22 -0
  433. package/dist/esm/transactions/executor/parallel.js +296 -0
  434. package/dist/esm/transactions/executor/parallel.js.map +7 -0
  435. package/dist/esm/transactions/executor/queue.d.ts +11 -0
  436. package/dist/esm/transactions/executor/queue.js +72 -0
  437. package/dist/esm/transactions/executor/queue.js.map +7 -0
  438. package/dist/esm/transactions/executor/serial.d.ts +27 -0
  439. package/dist/esm/transactions/executor/serial.js +120 -0
  440. package/dist/esm/transactions/executor/serial.js.map +7 -0
  441. package/dist/esm/transactions/hash.d.ts +7 -0
  442. package/dist/esm/transactions/hash.js +12 -0
  443. package/dist/esm/transactions/hash.js.map +7 -0
  444. package/dist/esm/transactions/index.d.ts +13 -0
  445. package/dist/esm/transactions/index.js +33 -0
  446. package/dist/esm/transactions/index.js.map +7 -0
  447. package/dist/esm/transactions/intents/CoinWithBalance.d.ts +6 -0
  448. package/dist/esm/transactions/intents/CoinWithBalance.js +148 -0
  449. package/dist/esm/transactions/intents/CoinWithBalance.js.map +7 -0
  450. package/dist/esm/transactions/json-rpc-resolver.d.ts +12 -0
  451. package/dist/esm/transactions/json-rpc-resolver.js +333 -0
  452. package/dist/esm/transactions/json-rpc-resolver.js.map +7 -0
  453. package/dist/esm/transactions/pure.d.ts +185 -0
  454. package/dist/esm/transactions/pure.js +21 -0
  455. package/dist/esm/transactions/pure.js.map +7 -0
  456. package/dist/esm/transactions/serializer.d.ts +7 -0
  457. package/dist/esm/transactions/serializer.js +156 -0
  458. package/dist/esm/transactions/serializer.js.map +7 -0
  459. package/dist/esm/transactions/utils.d.ts +8 -0
  460. package/dist/esm/transactions/utils.js +46 -0
  461. package/dist/esm/transactions/utils.js.map +7 -0
  462. package/dist/esm/utils/constants.d.ts +9 -0
  463. package/dist/esm/utils/constants.js +22 -0
  464. package/dist/esm/utils/constants.js.map +7 -0
  465. package/dist/esm/utils/format.d.ts +2 -0
  466. package/dist/esm/utils/format.js +16 -0
  467. package/dist/esm/utils/format.js.map +7 -0
  468. package/dist/esm/utils/index.d.ts +5 -0
  469. package/dist/esm/utils/index.js +52 -0
  470. package/dist/esm/utils/index.js.map +7 -0
  471. package/dist/esm/utils/sui-types.d.ts +27 -0
  472. package/dist/esm/utils/sui-types.js +70 -0
  473. package/dist/esm/utils/sui-types.js.map +7 -0
  474. package/dist/esm/utils/suins.d.ts +2 -0
  475. package/dist/esm/utils/suins.js +37 -0
  476. package/dist/esm/utils/suins.js.map +7 -0
  477. package/dist/esm/verify/index.d.ts +1 -0
  478. package/dist/esm/verify/index.js +15 -0
  479. package/dist/esm/verify/index.js.map +7 -0
  480. package/dist/esm/verify/verify.d.ts +11 -0
  481. package/dist/esm/verify/verify.js +81 -0
  482. package/dist/esm/verify/verify.js.map +7 -0
  483. package/dist/esm/version.d.ts +2 -0
  484. package/dist/esm/version.js +7 -0
  485. package/dist/esm/version.js.map +7 -0
  486. package/dist/esm/zklogin/address.d.ts +1 -0
  487. package/dist/esm/zklogin/address.js +24 -0
  488. package/dist/esm/zklogin/address.js.map +7 -0
  489. package/dist/esm/zklogin/bcs.d.ts +46 -0
  490. package/dist/esm/zklogin/bcs.js +22 -0
  491. package/dist/esm/zklogin/bcs.js.map +7 -0
  492. package/dist/esm/zklogin/index.d.ts +5 -0
  493. package/dist/esm/zklogin/index.js +13 -0
  494. package/dist/esm/zklogin/index.js.map +7 -0
  495. package/dist/esm/zklogin/jwt-utils.d.ts +5 -0
  496. package/dist/esm/zklogin/jwt-utils.js +82 -0
  497. package/dist/esm/zklogin/jwt-utils.js.map +7 -0
  498. package/dist/esm/zklogin/publickey.d.ts +69 -0
  499. package/dist/esm/zklogin/publickey.js +177 -0
  500. package/dist/esm/zklogin/publickey.js.map +7 -0
  501. package/dist/esm/zklogin/signature.d.ts +23 -0
  502. package/dist/esm/zklogin/signature.js +28 -0
  503. package/dist/esm/zklogin/signature.js.map +7 -0
  504. package/dist/esm/zklogin/utils.d.ts +2 -0
  505. package/dist/esm/zklogin/utils.js +26 -0
  506. package/dist/esm/zklogin/utils.js.map +7 -0
  507. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  508. package/dist/tsconfig.tsbuildinfo +1 -0
  509. package/faucet/package.json +6 -0
  510. package/graphql/package.json +6 -0
  511. package/graphql/schemas/2024.1/package.json +6 -0
  512. package/graphql/schemas/2024.4/package.json +6 -0
  513. package/keypairs/ed25519/package.json +6 -0
  514. package/keypairs/secp256k1/package.json +6 -0
  515. package/keypairs/secp256r1/package.json +6 -0
  516. package/multisig/package.json +6 -0
  517. package/package.json +160 -0
  518. package/src/bcs/bcs.ts +300 -0
  519. package/src/bcs/effects.ts +200 -0
  520. package/src/bcs/index.ts +87 -0
  521. package/src/bcs/type-tag-serializer.ts +106 -0
  522. package/src/bcs/types.ts +113 -0
  523. package/src/client/client.ts +814 -0
  524. package/src/client/errors.ts +45 -0
  525. package/src/client/http-transport.ts +130 -0
  526. package/src/client/index.ts +21 -0
  527. package/src/client/network.ts +17 -0
  528. package/src/client/rpc-websocket-client.ts +234 -0
  529. package/src/client/types/chain.ts +122 -0
  530. package/src/client/types/changes.ts +11 -0
  531. package/src/client/types/coins.ts +9 -0
  532. package/src/client/types/common.ts +5 -0
  533. package/src/client/types/generated.ts +1508 -0
  534. package/src/client/types/index.ts +9 -0
  535. package/src/client/types/params.ts +584 -0
  536. package/src/cryptography/index.ts +36 -0
  537. package/src/cryptography/intent.ts +22 -0
  538. package/src/cryptography/keypair.ts +130 -0
  539. package/src/cryptography/mnemonics.ts +49 -0
  540. package/src/cryptography/publickey.ts +133 -0
  541. package/src/cryptography/signature-scheme.ts +28 -0
  542. package/src/cryptography/signature.ts +86 -0
  543. package/src/faucet/faucet.ts +130 -0
  544. package/src/faucet/index.ts +10 -0
  545. package/src/graphql/client.ts +110 -0
  546. package/src/graphql/generated/2024-01/tada-env.d.ts +202 -0
  547. package/src/graphql/generated/2024.1/schema.graphql +4168 -0
  548. package/src/graphql/generated/2024.1/tada-env.d.ts +201 -0
  549. package/src/graphql/generated/2024.1/tsconfig.tada.json +11 -0
  550. package/src/graphql/generated/2024.4/schema.graphql +4183 -0
  551. package/src/graphql/generated/2024.4/tada-env.d.ts +202 -0
  552. package/src/graphql/generated/2024.4/tsconfig.tada.json +11 -0
  553. package/src/graphql/index.ts +12 -0
  554. package/src/graphql/schemas/2024.1/index.ts +17 -0
  555. package/src/graphql/schemas/2024.4/index.ts +17 -0
  556. package/src/graphql/types.ts +86 -0
  557. package/src/keypairs/ed25519/ed25519-hd-key.ts +93 -0
  558. package/src/keypairs/ed25519/index.ts +9 -0
  559. package/src/keypairs/ed25519/keypair.ts +151 -0
  560. package/src/keypairs/ed25519/publickey.ts +86 -0
  561. package/src/keypairs/secp256k1/index.ts +9 -0
  562. package/src/keypairs/secp256k1/keypair.ts +151 -0
  563. package/src/keypairs/secp256k1/publickey.ts +91 -0
  564. package/src/keypairs/secp256r1/index.ts +9 -0
  565. package/src/keypairs/secp256r1/keypair.ts +147 -0
  566. package/src/keypairs/secp256r1/publickey.ts +91 -0
  567. package/src/multisig/index.ts +5 -0
  568. package/src/multisig/publickey.ts +356 -0
  569. package/src/multisig/signer.ts +92 -0
  570. package/src/transactions/Commands.ts +178 -0
  571. package/src/transactions/Inputs.ts +68 -0
  572. package/src/transactions/ObjectCache.ts +296 -0
  573. package/src/transactions/Transaction.ts +553 -0
  574. package/src/transactions/TransactionData.ts +296 -0
  575. package/src/transactions/__tests__/Transaction.test.ts +184 -0
  576. package/src/transactions/__tests__/bcs.test.ts +205 -0
  577. package/src/transactions/data/internal.ts +321 -0
  578. package/src/transactions/data/v1.ts +501 -0
  579. package/src/transactions/data/v2.ts +146 -0
  580. package/src/transactions/executor/caching.ts +94 -0
  581. package/src/transactions/executor/parallel.ts +335 -0
  582. package/src/transactions/executor/queue.ts +65 -0
  583. package/src/transactions/executor/serial.ts +131 -0
  584. package/src/transactions/hash.ts +20 -0
  585. package/src/transactions/index.ts +41 -0
  586. package/src/transactions/intents/CoinWithBalance.ts +204 -0
  587. package/src/transactions/json-rpc-resolver.ts +482 -0
  588. package/src/transactions/pure.ts +32 -0
  589. package/src/transactions/serializer.ts +205 -0
  590. package/src/transactions/utils.ts +66 -0
  591. package/src/utils/constants.ts +15 -0
  592. package/src/utils/format.ts +19 -0
  593. package/src/utils/index.ts +29 -0
  594. package/src/utils/sui-types.ts +110 -0
  595. package/src/utils/suins.ts +43 -0
  596. package/src/verify/index.ts +11 -0
  597. package/src/verify/verify.ts +111 -0
  598. package/src/version.ts +7 -0
  599. package/src/zklogin/address.ts +27 -0
  600. package/src/zklogin/bcs.ts +26 -0
  601. package/src/zklogin/index.ts +8 -0
  602. package/src/zklogin/jwt-utils.ts +113 -0
  603. package/src/zklogin/publickey.ts +190 -0
  604. package/src/zklogin/signature.ts +37 -0
  605. package/src/zklogin/utils.ts +33 -0
  606. package/transactions/package.json +6 -0
  607. package/utils/package.json +6 -0
  608. package/verify/package.json +6 -0
  609. package/zklogin/package.json +6 -0
@@ -0,0 +1,86 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export type MoveData =
5
+ | { Address: string }
6
+ | { UID: string }
7
+ | { ID: string }
8
+ | { Bool: boolean }
9
+ | { Number: string }
10
+ | { String: string }
11
+ | { Vector: [MoveData] }
12
+ | { Option: MoveData | null }
13
+ | { Struct: [{ name: string; value: MoveData }] };
14
+
15
+ export type MoveTypeLayout =
16
+ | 'address'
17
+ | 'bool'
18
+ | 'u8'
19
+ | 'u16'
20
+ | 'u32'
21
+ | 'u64'
22
+ | 'u128'
23
+ | 'u256'
24
+ | { vector: MoveTypeLayout }
25
+ | {
26
+ struct: {
27
+ type: string;
28
+ fields: [{ name: string; layout: MoveTypeLayout }];
29
+ };
30
+ };
31
+
32
+ export type MoveTypeSignature =
33
+ | 'address'
34
+ | 'bool'
35
+ | 'u8'
36
+ | 'u16'
37
+ | 'u32'
38
+ | 'u64'
39
+ | 'u128'
40
+ | 'u256'
41
+ | { vector: MoveTypeSignature }
42
+ | {
43
+ datatype: {
44
+ package: string;
45
+ module: string;
46
+ type: string;
47
+ typeParameters: [MoveTypeSignature];
48
+ };
49
+ };
50
+
51
+ export type OpenMoveTypeSignature = {
52
+ ref?: ('&' | '&mut') | null;
53
+ body: OpenMoveTypeSignatureBody;
54
+ };
55
+
56
+ export type OpenMoveTypeSignatureBody =
57
+ | 'address'
58
+ | 'bool'
59
+ | 'u8'
60
+ | 'u16'
61
+ | 'u32'
62
+ | 'u64'
63
+ | 'u128'
64
+ | 'u256'
65
+ | { vector: OpenMoveTypeSignatureBody }
66
+ | {
67
+ datatype: {
68
+ package: string;
69
+ module: string;
70
+ type: string;
71
+ typeParameters: [OpenMoveTypeSignatureBody];
72
+ };
73
+ }
74
+ | { typeParameter: number };
75
+
76
+ export interface CustomScalars {
77
+ BigInt: string;
78
+ Base64: string;
79
+ DateTime: string;
80
+ JSON: unknown;
81
+ MoveData: MoveData;
82
+ MoveTypeLayout: MoveTypeLayout;
83
+ MoveTypeSignature: MoveTypeSignature;
84
+ OpenMoveTypeSignature: OpenMoveTypeSignature;
85
+ SuiAddress: string;
86
+ }
@@ -0,0 +1,93 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // This is adapted from https://github.com/alepop/ed25519-hd-key replacing create-hmac
5
+ // with @noble/hashes to be browser compatible.
6
+
7
+ import { fromHEX } from '@mysten/bcs';
8
+ import { hmac } from '@noble/hashes/hmac';
9
+ import { sha512 } from '@noble/hashes/sha512';
10
+ import nacl from 'tweetnacl';
11
+
12
+ type Hex = string;
13
+ type Path = string;
14
+
15
+ type Keys = {
16
+ key: Uint8Array;
17
+ chainCode: Uint8Array;
18
+ };
19
+
20
+ const ED25519_CURVE = 'ed25519 seed';
21
+ const HARDENED_OFFSET = 0x80000000;
22
+
23
+ export const pathRegex = new RegExp("^m(\\/[0-9]+')+$");
24
+
25
+ export const replaceDerive = (val: string): string => val.replace("'", '');
26
+
27
+ export const getMasterKeyFromSeed = (seed: Hex): Keys => {
28
+ const h = hmac.create(sha512, ED25519_CURVE);
29
+ const I = h.update(fromHEX(seed)).digest();
30
+ const IL = I.slice(0, 32);
31
+ const IR = I.slice(32);
32
+ return {
33
+ key: IL,
34
+ chainCode: IR,
35
+ };
36
+ };
37
+
38
+ const CKDPriv = ({ key, chainCode }: Keys, index: number): Keys => {
39
+ const indexBuffer = new ArrayBuffer(4);
40
+ const cv = new DataView(indexBuffer);
41
+ cv.setUint32(0, index);
42
+
43
+ const data = new Uint8Array(1 + key.length + indexBuffer.byteLength);
44
+ data.set(new Uint8Array(1).fill(0));
45
+ data.set(key, 1);
46
+ data.set(new Uint8Array(indexBuffer, 0, indexBuffer.byteLength), key.length + 1);
47
+
48
+ const I = hmac.create(sha512, chainCode).update(data).digest();
49
+ const IL = I.slice(0, 32);
50
+ const IR = I.slice(32);
51
+ return {
52
+ key: IL,
53
+ chainCode: IR,
54
+ };
55
+ };
56
+
57
+ export const getPublicKey = (privateKey: Uint8Array, withZeroByte = true): Uint8Array => {
58
+ const keyPair = nacl.sign.keyPair.fromSeed(privateKey);
59
+ const signPk = keyPair.secretKey.subarray(32);
60
+ const newArr = new Uint8Array(signPk.length + 1);
61
+ newArr.set([0]);
62
+ newArr.set(signPk, 1);
63
+ return withZeroByte ? newArr : signPk;
64
+ };
65
+
66
+ export const isValidPath = (path: string): boolean => {
67
+ if (!pathRegex.test(path)) {
68
+ return false;
69
+ }
70
+ return !path
71
+ .split('/')
72
+ .slice(1)
73
+ .map(replaceDerive)
74
+ .some(isNaN as any /* ts T_T*/);
75
+ };
76
+
77
+ export const derivePath = (path: Path, seed: Hex, offset = HARDENED_OFFSET): Keys => {
78
+ if (!isValidPath(path)) {
79
+ throw new Error('Invalid derivation path');
80
+ }
81
+
82
+ const { key, chainCode } = getMasterKeyFromSeed(seed);
83
+ const segments = path
84
+ .split('/')
85
+ .slice(1)
86
+ .map(replaceDerive)
87
+ .map((el) => parseInt(el, 10));
88
+
89
+ return segments.reduce((parentKeys, segment) => CKDPriv(parentKeys, segment + offset), {
90
+ key,
91
+ chainCode,
92
+ });
93
+ };
@@ -0,0 +1,9 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export {
5
+ DEFAULT_ED25519_DERIVATION_PATH,
6
+ Ed25519Keypair,
7
+ type Ed25519KeypairData,
8
+ } from './keypair.js';
9
+ export { Ed25519PublicKey } from './publickey.js';
@@ -0,0 +1,151 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import nacl from 'tweetnacl';
5
+
6
+ import { encodeSuiPrivateKey, Keypair, PRIVATE_KEY_SIZE } from '../../cryptography/keypair.js';
7
+ import { isValidHardenedPath, mnemonicToSeedHex } from '../../cryptography/mnemonics.js';
8
+ import type { SignatureScheme } from '../../cryptography/signature-scheme.js';
9
+ import { derivePath } from './ed25519-hd-key.js';
10
+ import { Ed25519PublicKey } from './publickey.js';
11
+
12
+ export const DEFAULT_ED25519_DERIVATION_PATH = "m/44'/784'/0'/0'/0'";
13
+
14
+ /**
15
+ * Ed25519 Keypair data. The publickey is the 32-byte public key and
16
+ * the secretkey is 64-byte, where the first 32 bytes is the secret
17
+ * key and the last 32 bytes is the public key.
18
+ */
19
+ export interface Ed25519KeypairData {
20
+ publicKey: Uint8Array;
21
+ secretKey: Uint8Array;
22
+ }
23
+
24
+ /**
25
+ * An Ed25519 Keypair used for signing transactions.
26
+ */
27
+ export class Ed25519Keypair extends Keypair {
28
+ private keypair: Ed25519KeypairData;
29
+
30
+ /**
31
+ * Create a new Ed25519 keypair instance.
32
+ * Generate random keypair if no {@link Ed25519Keypair} is provided.
33
+ *
34
+ * @param keypair Ed25519 keypair
35
+ */
36
+ constructor(keypair?: Ed25519KeypairData) {
37
+ super();
38
+ if (keypair) {
39
+ this.keypair = keypair;
40
+ } else {
41
+ this.keypair = nacl.sign.keyPair();
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Get the key scheme of the keypair ED25519
47
+ */
48
+ getKeyScheme(): SignatureScheme {
49
+ return 'ED25519';
50
+ }
51
+
52
+ /**
53
+ * Generate a new random Ed25519 keypair
54
+ */
55
+ static generate(): Ed25519Keypair {
56
+ return new Ed25519Keypair(nacl.sign.keyPair());
57
+ }
58
+
59
+ /**
60
+ * Create a Ed25519 keypair from a raw secret key byte array, also known as seed.
61
+ * This is NOT the private scalar which is result of hashing and bit clamping of
62
+ * the raw secret key.
63
+ *
64
+ * @throws error if the provided secret key is invalid and validation is not skipped.
65
+ *
66
+ * @param secretKey secret key byte array
67
+ * @param options: skip secret key validation
68
+ */
69
+ static fromSecretKey(
70
+ secretKey: Uint8Array,
71
+ options?: { skipValidation?: boolean },
72
+ ): Ed25519Keypair {
73
+ const secretKeyLength = secretKey.length;
74
+ if (secretKeyLength !== PRIVATE_KEY_SIZE) {
75
+ throw new Error(
76
+ `Wrong secretKey size. Expected ${PRIVATE_KEY_SIZE} bytes, got ${secretKeyLength}.`,
77
+ );
78
+ }
79
+ const keypair = nacl.sign.keyPair.fromSeed(secretKey);
80
+ if (!options || !options.skipValidation) {
81
+ const encoder = new TextEncoder();
82
+ const signData = encoder.encode('sui validation');
83
+ const signature = nacl.sign.detached(signData, keypair.secretKey);
84
+ if (!nacl.sign.detached.verify(signData, signature, keypair.publicKey)) {
85
+ throw new Error('provided secretKey is invalid');
86
+ }
87
+ }
88
+ return new Ed25519Keypair(keypair);
89
+ }
90
+
91
+ /**
92
+ * The public key for this Ed25519 keypair
93
+ */
94
+ getPublicKey(): Ed25519PublicKey {
95
+ return new Ed25519PublicKey(this.keypair.publicKey);
96
+ }
97
+
98
+ /**
99
+ * The Bech32 secret key string for this Ed25519 keypair
100
+ */
101
+ getSecretKey(): string {
102
+ return encodeSuiPrivateKey(
103
+ this.keypair.secretKey.slice(0, PRIVATE_KEY_SIZE),
104
+ this.getKeyScheme(),
105
+ );
106
+ }
107
+
108
+ /**
109
+ * Return the signature for the provided data using Ed25519.
110
+ */
111
+ async sign(data: Uint8Array) {
112
+ return nacl.sign.detached(data, this.keypair.secretKey);
113
+ }
114
+
115
+ /**
116
+ * Derive Ed25519 keypair from mnemonics and path. The mnemonics must be normalized
117
+ * and validated against the english wordlist.
118
+ *
119
+ * If path is none, it will default to m/44'/784'/0'/0'/0', otherwise the path must
120
+ * be compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.
121
+ */
122
+ static deriveKeypair(mnemonics: string, path?: string): Ed25519Keypair {
123
+ if (path == null) {
124
+ path = DEFAULT_ED25519_DERIVATION_PATH;
125
+ }
126
+ if (!isValidHardenedPath(path)) {
127
+ throw new Error('Invalid derivation path');
128
+ }
129
+ const { key } = derivePath(path, mnemonicToSeedHex(mnemonics));
130
+
131
+ return Ed25519Keypair.fromSecretKey(key);
132
+ }
133
+
134
+ /**
135
+ * Derive Ed25519 keypair from mnemonicSeed and path.
136
+ *
137
+ * If path is none, it will default to m/44'/784'/0'/0'/0', otherwise the path must
138
+ * be compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.
139
+ */
140
+ static deriveKeypairFromSeed(seedHex: string, path?: string): Ed25519Keypair {
141
+ if (path == null) {
142
+ path = DEFAULT_ED25519_DERIVATION_PATH;
143
+ }
144
+ if (!isValidHardenedPath(path)) {
145
+ throw new Error('Invalid derivation path');
146
+ }
147
+ const { key } = derivePath(path, seedHex);
148
+
149
+ return Ed25519Keypair.fromSecretKey(key);
150
+ }
151
+ }
@@ -0,0 +1,86 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { fromB64 } from '@mysten/bcs';
5
+ import nacl from 'tweetnacl';
6
+
7
+ import type { PublicKeyInitData } from '../../cryptography/publickey.js';
8
+ import { bytesEqual, PublicKey } from '../../cryptography/publickey.js';
9
+ import { SIGNATURE_SCHEME_TO_FLAG } from '../../cryptography/signature-scheme.js';
10
+ import { parseSerializedSignature } from '../../cryptography/signature.js';
11
+
12
+ const PUBLIC_KEY_SIZE = 32;
13
+
14
+ /**
15
+ * An Ed25519 public key
16
+ */
17
+ export class Ed25519PublicKey extends PublicKey {
18
+ static SIZE = PUBLIC_KEY_SIZE;
19
+ private data: Uint8Array;
20
+
21
+ /**
22
+ * Create a new Ed25519PublicKey object
23
+ * @param value ed25519 public key as buffer or base-64 encoded string
24
+ */
25
+ constructor(value: PublicKeyInitData) {
26
+ super();
27
+
28
+ if (typeof value === 'string') {
29
+ this.data = fromB64(value);
30
+ } else if (value instanceof Uint8Array) {
31
+ this.data = value;
32
+ } else {
33
+ this.data = Uint8Array.from(value);
34
+ }
35
+
36
+ if (this.data.length !== PUBLIC_KEY_SIZE) {
37
+ throw new Error(
38
+ `Invalid public key input. Expected ${PUBLIC_KEY_SIZE} bytes, got ${this.data.length}`,
39
+ );
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Checks if two Ed25519 public keys are equal
45
+ */
46
+ override equals(publicKey: Ed25519PublicKey): boolean {
47
+ return super.equals(publicKey);
48
+ }
49
+
50
+ /**
51
+ * Return the byte array representation of the Ed25519 public key
52
+ */
53
+ toRawBytes(): Uint8Array {
54
+ return this.data;
55
+ }
56
+
57
+ /**
58
+ * Return the Sui address associated with this Ed25519 public key
59
+ */
60
+ flag(): number {
61
+ return SIGNATURE_SCHEME_TO_FLAG['ED25519'];
62
+ }
63
+
64
+ /**
65
+ * Verifies that the signature is valid for for the provided message
66
+ */
67
+ async verify(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {
68
+ let bytes;
69
+ if (typeof signature === 'string') {
70
+ const parsed = parseSerializedSignature(signature);
71
+ if (parsed.signatureScheme !== 'ED25519') {
72
+ throw new Error('Invalid signature scheme');
73
+ }
74
+
75
+ if (!bytesEqual(this.toRawBytes(), parsed.publicKey)) {
76
+ throw new Error('Signature does not match public key');
77
+ }
78
+
79
+ bytes = parsed.signature;
80
+ } else {
81
+ bytes = signature;
82
+ }
83
+
84
+ return nacl.sign.detached.verify(message, bytes, this.toRawBytes());
85
+ }
86
+ }
@@ -0,0 +1,9 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export {
5
+ DEFAULT_SECP256K1_DERIVATION_PATH,
6
+ Secp256k1Keypair,
7
+ type Secp256k1KeypairData,
8
+ } from './keypair.js';
9
+ export { Secp256k1PublicKey } from './publickey.js';
@@ -0,0 +1,151 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { secp256k1 } from '@noble/curves/secp256k1';
5
+ import { blake2b } from '@noble/hashes/blake2b';
6
+ import { sha256 } from '@noble/hashes/sha256';
7
+ import { bytesToHex } from '@noble/hashes/utils';
8
+ import { HDKey } from '@scure/bip32';
9
+
10
+ import { encodeSuiPrivateKey, Keypair } from '../../cryptography/keypair.js';
11
+ import { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';
12
+ import type { PublicKey } from '../../cryptography/publickey.js';
13
+ import type { SignatureScheme } from '../../cryptography/signature-scheme.js';
14
+ import { Secp256k1PublicKey } from './publickey.js';
15
+
16
+ export const DEFAULT_SECP256K1_DERIVATION_PATH = "m/54'/784'/0'/0/0";
17
+
18
+ /**
19
+ * Secp256k1 Keypair data
20
+ */
21
+ export interface Secp256k1KeypairData {
22
+ publicKey: Uint8Array;
23
+ secretKey: Uint8Array;
24
+ }
25
+
26
+ /**
27
+ * An Secp256k1 Keypair used for signing transactions.
28
+ */
29
+ export class Secp256k1Keypair extends Keypair {
30
+ private keypair: Secp256k1KeypairData;
31
+
32
+ /**
33
+ * Create a new keypair instance.
34
+ * Generate random keypair if no {@link Secp256k1Keypair} is provided.
35
+ *
36
+ * @param keypair secp256k1 keypair
37
+ */
38
+ constructor(keypair?: Secp256k1KeypairData) {
39
+ super();
40
+ if (keypair) {
41
+ this.keypair = keypair;
42
+ } else {
43
+ const secretKey: Uint8Array = secp256k1.utils.randomPrivateKey();
44
+ const publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);
45
+
46
+ this.keypair = { publicKey, secretKey };
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Get the key scheme of the keypair Secp256k1
52
+ */
53
+ getKeyScheme(): SignatureScheme {
54
+ return 'Secp256k1';
55
+ }
56
+
57
+ /**
58
+ * Generate a new random keypair
59
+ */
60
+ static generate(): Secp256k1Keypair {
61
+ return new Secp256k1Keypair();
62
+ }
63
+
64
+ /**
65
+ * Create a keypair from a raw secret key byte array.
66
+ *
67
+ * This method should only be used to recreate a keypair from a previously
68
+ * generated secret key. Generating keypairs from a random seed should be done
69
+ * with the {@link Keypair.fromSeed} method.
70
+ *
71
+ * @throws error if the provided secret key is invalid and validation is not skipped.
72
+ *
73
+ * @param secretKey secret key byte array
74
+ * @param options: skip secret key validation
75
+ */
76
+
77
+ static fromSecretKey(
78
+ secretKey: Uint8Array,
79
+ options?: { skipValidation?: boolean },
80
+ ): Secp256k1Keypair {
81
+ const publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);
82
+ if (!options || !options.skipValidation) {
83
+ const encoder = new TextEncoder();
84
+ const signData = encoder.encode('sui validation');
85
+ const msgHash = bytesToHex(blake2b(signData, { dkLen: 32 }));
86
+ const signature = secp256k1.sign(msgHash, secretKey);
87
+ if (!secp256k1.verify(signature, msgHash, publicKey, { lowS: true })) {
88
+ throw new Error('Provided secretKey is invalid');
89
+ }
90
+ }
91
+ return new Secp256k1Keypair({ publicKey, secretKey });
92
+ }
93
+
94
+ /**
95
+ * Generate a keypair from a 32 byte seed.
96
+ *
97
+ * @param seed seed byte array
98
+ */
99
+ static fromSeed(seed: Uint8Array): Secp256k1Keypair {
100
+ let publicKey = secp256k1.getPublicKey(seed, true);
101
+ return new Secp256k1Keypair({ publicKey, secretKey: seed });
102
+ }
103
+
104
+ /**
105
+ * The public key for this keypair
106
+ */
107
+ getPublicKey(): PublicKey {
108
+ return new Secp256k1PublicKey(this.keypair.publicKey);
109
+ }
110
+ /**
111
+ * The Bech32 secret key string for this Secp256k1 keypair
112
+ */
113
+ getSecretKey(): string {
114
+ return encodeSuiPrivateKey(this.keypair.secretKey, this.getKeyScheme());
115
+ }
116
+
117
+ /**
118
+ * Return the signature for the provided data.
119
+ */
120
+ async sign(data: Uint8Array) {
121
+ const msgHash = sha256(data);
122
+ const sig = secp256k1.sign(msgHash, this.keypair.secretKey, {
123
+ lowS: true,
124
+ });
125
+ return sig.toCompactRawBytes();
126
+ }
127
+
128
+ /**
129
+ * Derive Secp256k1 keypair from mnemonics and path. The mnemonics must be normalized
130
+ * and validated against the english wordlist.
131
+ *
132
+ * If path is none, it will default to m/54'/784'/0'/0/0, otherwise the path must
133
+ * be compliant to BIP-32 in form m/54'/784'/{account_index}'/{change_index}/{address_index}.
134
+ */
135
+ static deriveKeypair(mnemonics: string, path?: string): Secp256k1Keypair {
136
+ if (path == null) {
137
+ path = DEFAULT_SECP256K1_DERIVATION_PATH;
138
+ }
139
+ if (!isValidBIP32Path(path)) {
140
+ throw new Error('Invalid derivation path');
141
+ }
142
+ const key = HDKey.fromMasterSeed(mnemonicToSeed(mnemonics)).derive(path);
143
+ if (key.publicKey == null || key.privateKey == null) {
144
+ throw new Error('Invalid key');
145
+ }
146
+ return new Secp256k1Keypair({
147
+ publicKey: key.publicKey,
148
+ secretKey: key.privateKey,
149
+ });
150
+ }
151
+ }
@@ -0,0 +1,91 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { fromB64 } from '@mysten/bcs';
5
+ import { secp256k1 } from '@noble/curves/secp256k1';
6
+ import { sha256 } from '@noble/hashes/sha256';
7
+
8
+ import { bytesEqual, PublicKey } from '../../cryptography/publickey.js';
9
+ import type { PublicKeyInitData } from '../../cryptography/publickey.js';
10
+ import { SIGNATURE_SCHEME_TO_FLAG } from '../../cryptography/signature-scheme.js';
11
+ import { parseSerializedSignature } from '../../cryptography/signature.js';
12
+
13
+ const SECP256K1_PUBLIC_KEY_SIZE = 33;
14
+
15
+ /**
16
+ * A Secp256k1 public key
17
+ */
18
+ export class Secp256k1PublicKey extends PublicKey {
19
+ static SIZE = SECP256K1_PUBLIC_KEY_SIZE;
20
+ private data: Uint8Array;
21
+
22
+ /**
23
+ * Create a new Secp256k1PublicKey object
24
+ * @param value secp256k1 public key as buffer or base-64 encoded string
25
+ */
26
+ constructor(value: PublicKeyInitData) {
27
+ super();
28
+
29
+ if (typeof value === 'string') {
30
+ this.data = fromB64(value);
31
+ } else if (value instanceof Uint8Array) {
32
+ this.data = value;
33
+ } else {
34
+ this.data = Uint8Array.from(value);
35
+ }
36
+
37
+ if (this.data.length !== SECP256K1_PUBLIC_KEY_SIZE) {
38
+ throw new Error(
39
+ `Invalid public key input. Expected ${SECP256K1_PUBLIC_KEY_SIZE} bytes, got ${this.data.length}`,
40
+ );
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Checks if two Secp256k1 public keys are equal
46
+ */
47
+ override equals(publicKey: Secp256k1PublicKey): boolean {
48
+ return super.equals(publicKey);
49
+ }
50
+
51
+ /**
52
+ * Return the byte array representation of the Secp256k1 public key
53
+ */
54
+ toRawBytes(): Uint8Array {
55
+ return this.data;
56
+ }
57
+
58
+ /**
59
+ * Return the Sui address associated with this Secp256k1 public key
60
+ */
61
+ flag(): number {
62
+ return SIGNATURE_SCHEME_TO_FLAG['Secp256k1'];
63
+ }
64
+
65
+ /**
66
+ * Verifies that the signature is valid for for the provided message
67
+ */
68
+ async verify(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {
69
+ let bytes;
70
+ if (typeof signature === 'string') {
71
+ const parsed = parseSerializedSignature(signature);
72
+ if (parsed.signatureScheme !== 'Secp256k1') {
73
+ throw new Error('Invalid signature scheme');
74
+ }
75
+
76
+ if (!bytesEqual(this.toRawBytes(), parsed.publicKey)) {
77
+ throw new Error('Signature does not match public key');
78
+ }
79
+
80
+ bytes = parsed.signature;
81
+ } else {
82
+ bytes = signature;
83
+ }
84
+
85
+ return secp256k1.verify(
86
+ secp256k1.Signature.fromCompact(bytes),
87
+ sha256(message),
88
+ this.toRawBytes(),
89
+ );
90
+ }
91
+ }
@@ -0,0 +1,9 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export {
5
+ DEFAULT_SECP256R1_DERIVATION_PATH,
6
+ Secp256r1Keypair,
7
+ type Secp256r1KeypairData,
8
+ } from './keypair.js';
9
+ export { Secp256r1PublicKey } from './publickey.js';