@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,147 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { secp256r1 } from '@noble/curves/p256';
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 { Secp256r1PublicKey } from './publickey.js';
15
+
16
+ export const DEFAULT_SECP256R1_DERIVATION_PATH = "m/74'/784'/0'/0/0";
17
+
18
+ /**
19
+ * Secp256r1 Keypair data
20
+ */
21
+ export interface Secp256r1KeypairData {
22
+ publicKey: Uint8Array;
23
+ secretKey: Uint8Array;
24
+ }
25
+
26
+ /**
27
+ * An Secp256r1 Keypair used for signing transactions.
28
+ */
29
+ export class Secp256r1Keypair extends Keypair {
30
+ private keypair: Secp256r1KeypairData;
31
+
32
+ /**
33
+ * Create a new keypair instance.
34
+ * Generate random keypair if no {@link Secp256r1Keypair} is provided.
35
+ *
36
+ * @param keypair Secp256r1 keypair
37
+ */
38
+ constructor(keypair?: Secp256r1KeypairData) {
39
+ super();
40
+ if (keypair) {
41
+ this.keypair = keypair;
42
+ } else {
43
+ const secretKey: Uint8Array = secp256r1.utils.randomPrivateKey();
44
+ const publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);
45
+
46
+ this.keypair = { publicKey, secretKey };
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Get the key scheme of the keypair Secp256r1
52
+ */
53
+ getKeyScheme(): SignatureScheme {
54
+ return 'Secp256r1';
55
+ }
56
+
57
+ /**
58
+ * Generate a new random keypair
59
+ */
60
+ static generate(): Secp256r1Keypair {
61
+ return new Secp256r1Keypair();
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
+ ): Secp256r1Keypair {
81
+ const publicKey: Uint8Array = secp256r1.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 = secp256r1.sign(msgHash, secretKey, { lowS: true });
87
+ if (!secp256r1.verify(signature, msgHash, publicKey, { lowS: true })) {
88
+ throw new Error('Provided secretKey is invalid');
89
+ }
90
+ }
91
+ return new Secp256r1Keypair({ 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): Secp256r1Keypair {
100
+ let publicKey = secp256r1.getPublicKey(seed, true);
101
+ return new Secp256r1Keypair({ publicKey, secretKey: seed });
102
+ }
103
+
104
+ /**
105
+ * The public key for this keypair
106
+ */
107
+ getPublicKey(): PublicKey {
108
+ return new Secp256r1PublicKey(this.keypair.publicKey);
109
+ }
110
+
111
+ /**
112
+ * The Bech32 secret key string for this Secp256r1 keypair
113
+ */
114
+ getSecretKey(): string {
115
+ return encodeSuiPrivateKey(this.keypair.secretKey, this.getKeyScheme());
116
+ }
117
+
118
+ /**
119
+ * Return the signature for the provided data.
120
+ */
121
+ async sign(data: Uint8Array) {
122
+ const msgHash = sha256(data);
123
+ const sig = secp256r1.sign(msgHash, this.keypair.secretKey, {
124
+ lowS: true,
125
+ });
126
+ return sig.toCompactRawBytes();
127
+ }
128
+
129
+ /**
130
+ * Derive Secp256r1 keypair from mnemonics and path. The mnemonics must be normalized
131
+ * and validated against the english wordlist.
132
+ *
133
+ * If path is none, it will default to m/74'/784'/0'/0/0, otherwise the path must
134
+ * be compliant to BIP-32 in form m/74'/784'/{account_index}'/{change_index}/{address_index}.
135
+ */
136
+ static deriveKeypair(mnemonics: string, path?: string): Secp256r1Keypair {
137
+ if (path == null) {
138
+ path = DEFAULT_SECP256R1_DERIVATION_PATH;
139
+ }
140
+ if (!isValidBIP32Path(path)) {
141
+ throw new Error('Invalid derivation path');
142
+ }
143
+ // We use HDKey which is hardcoded to use Secp256k1 but since we only need the 32 bytes for the private key it's okay to use here as well.
144
+ const privateKey = HDKey.fromMasterSeed(mnemonicToSeed(mnemonics)).derive(path).privateKey;
145
+ return Secp256r1Keypair.fromSecretKey(privateKey!);
146
+ }
147
+ }
@@ -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 { secp256r1 } from '@noble/curves/p256';
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 SECP256R1_PUBLIC_KEY_SIZE = 33;
14
+
15
+ /**
16
+ * A Secp256r1 public key
17
+ */
18
+ export class Secp256r1PublicKey extends PublicKey {
19
+ static SIZE = SECP256R1_PUBLIC_KEY_SIZE;
20
+ private data: Uint8Array;
21
+
22
+ /**
23
+ * Create a new Secp256r1PublicKey object
24
+ * @param value secp256r1 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 !== SECP256R1_PUBLIC_KEY_SIZE) {
38
+ throw new Error(
39
+ `Invalid public key input. Expected ${SECP256R1_PUBLIC_KEY_SIZE} bytes, got ${this.data.length}`,
40
+ );
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Checks if two Secp256r1 public keys are equal
46
+ */
47
+ override equals(publicKey: Secp256r1PublicKey): boolean {
48
+ return super.equals(publicKey);
49
+ }
50
+
51
+ /**
52
+ * Return the byte array representation of the Secp256r1 public key
53
+ */
54
+ toRawBytes(): Uint8Array {
55
+ return this.data;
56
+ }
57
+
58
+ /**
59
+ * Return the Sui address associated with this Secp256r1 public key
60
+ */
61
+ flag(): number {
62
+ return SIGNATURE_SCHEME_TO_FLAG['Secp256r1'];
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 !== 'Secp256r1') {
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 secp256r1.verify(
86
+ secp256r1.Signature.fromCompact(bytes),
87
+ sha256(message),
88
+ this.toRawBytes(),
89
+ );
90
+ }
91
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { MultiSigSigner } from './signer.js';
5
+ export { type MultiSigStruct, MultiSigPublicKey, parsePartialSignatures } from './publickey.js';
@@ -0,0 +1,356 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { fromB64, toB64 } from '@mysten/bcs';
5
+ import { blake2b } from '@noble/hashes/blake2b';
6
+ import { bytesToHex } from '@noble/hashes/utils';
7
+
8
+ import { bcs } from '../bcs/index.js';
9
+ import type { Signer } from '../cryptography/keypair.js';
10
+ import { bytesEqual, PublicKey } from '../cryptography/publickey.js';
11
+ import {
12
+ SIGNATURE_FLAG_TO_SCHEME,
13
+ SIGNATURE_SCHEME_TO_FLAG,
14
+ } from '../cryptography/signature-scheme.js';
15
+ import type { SignatureFlag, SignatureScheme } from '../cryptography/signature-scheme.js';
16
+ import { parseSerializedSignature } from '../cryptography/signature.js';
17
+ import type { SuiGraphQLClient } from '../graphql/client.js';
18
+ import { normalizeSuiAddress } from '../utils/sui-types.js';
19
+ // eslint-disable-next-line import/no-cycle
20
+ import { publicKeyFromRawBytes } from '../verify/index.js';
21
+ import { toZkLoginPublicIdentifier } from '../zklogin/publickey.js';
22
+ import { MultiSigSigner } from './signer.js';
23
+
24
+ type CompressedSignature =
25
+ | { ED25519: number[] }
26
+ | { Secp256k1: number[] }
27
+ | { Secp256r1: number[] }
28
+ | { ZkLogin: number[] };
29
+
30
+ type PublicKeyEnum =
31
+ | { ED25519: number[] }
32
+ | { Secp256k1: number[] }
33
+ | { Secp256r1: number[] }
34
+ | { ZkLogin: number[] };
35
+
36
+ type PubkeyEnumWeightPair = {
37
+ pubKey: PublicKeyEnum;
38
+ weight: number;
39
+ };
40
+
41
+ type MultiSigPublicKeyStruct = {
42
+ pk_map: PubkeyEnumWeightPair[];
43
+ threshold: number;
44
+ };
45
+
46
+ export type MultiSigStruct = {
47
+ sigs: CompressedSignature[];
48
+ bitmap: number;
49
+ multisig_pk: MultiSigPublicKeyStruct;
50
+ };
51
+
52
+ type ParsedPartialMultiSigSignature = {
53
+ signatureScheme: SignatureScheme;
54
+ signature: Uint8Array;
55
+ publicKey: PublicKey;
56
+ weight: number;
57
+ };
58
+
59
+ export const MAX_SIGNER_IN_MULTISIG = 10;
60
+ export const MIN_SIGNER_IN_MULTISIG = 1;
61
+ /**
62
+ * A MultiSig public key
63
+ */
64
+ export class MultiSigPublicKey extends PublicKey {
65
+ private rawBytes: Uint8Array;
66
+ private multisigPublicKey: MultiSigPublicKeyStruct;
67
+ private publicKeys: {
68
+ weight: number;
69
+ publicKey: PublicKey;
70
+ }[];
71
+ /**
72
+ * Create a new MultiSigPublicKey object
73
+ */
74
+ constructor(
75
+ /**
76
+ * MultiSig public key as buffer or base-64 encoded string
77
+ */
78
+ value: string | Uint8Array | MultiSigPublicKeyStruct,
79
+ options: { client?: SuiGraphQLClient } = {},
80
+ ) {
81
+ super();
82
+
83
+ if (typeof value === 'string') {
84
+ this.rawBytes = fromB64(value);
85
+
86
+ this.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);
87
+ } else if (value instanceof Uint8Array) {
88
+ this.rawBytes = value;
89
+ this.multisigPublicKey = bcs.MultiSigPublicKey.parse(this.rawBytes);
90
+ } else {
91
+ this.multisigPublicKey = value;
92
+ this.rawBytes = bcs.MultiSigPublicKey.serialize(value).toBytes();
93
+ }
94
+ if (this.multisigPublicKey.threshold < 1) {
95
+ throw new Error('Invalid threshold');
96
+ }
97
+
98
+ const seenPublicKeys = new Set<string>();
99
+
100
+ this.publicKeys = this.multisigPublicKey.pk_map.map(({ pubKey, weight }) => {
101
+ const [scheme, bytes] = Object.entries(pubKey).filter(([name]) => name !== '$kind')[0] as [
102
+ SignatureScheme,
103
+ number[],
104
+ ];
105
+ const publicKeyStr = Uint8Array.from(bytes).toString();
106
+
107
+ if (seenPublicKeys.has(publicKeyStr)) {
108
+ throw new Error(`Multisig does not support duplicate public keys`);
109
+ }
110
+ seenPublicKeys.add(publicKeyStr);
111
+
112
+ if (weight < 1) {
113
+ throw new Error(`Invalid weight`);
114
+ }
115
+
116
+ return {
117
+ publicKey: publicKeyFromRawBytes(scheme, Uint8Array.from(bytes), options),
118
+ weight,
119
+ };
120
+ });
121
+
122
+ const totalWeight = this.publicKeys.reduce((sum, { weight }) => sum + weight, 0);
123
+
124
+ if (this.multisigPublicKey.threshold > totalWeight) {
125
+ throw new Error(`Unreachable threshold`);
126
+ }
127
+
128
+ if (this.publicKeys.length > MAX_SIGNER_IN_MULTISIG) {
129
+ throw new Error(`Max number of signers in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);
130
+ }
131
+
132
+ if (this.publicKeys.length < MIN_SIGNER_IN_MULTISIG) {
133
+ throw new Error(`Min number of signers in a multisig is ${MIN_SIGNER_IN_MULTISIG}`);
134
+ }
135
+ }
136
+ /**
137
+ * A static method to create a new MultiSig publickey instance from a set of public keys and their associated weights pairs and threshold.
138
+ */
139
+
140
+ static fromPublicKeys({
141
+ threshold,
142
+ publicKeys,
143
+ }: {
144
+ threshold: number;
145
+ publicKeys: { publicKey: PublicKey; weight: number }[];
146
+ }) {
147
+ return new MultiSigPublicKey({
148
+ pk_map: publicKeys.map(({ publicKey, weight }) => {
149
+ const scheme = SIGNATURE_FLAG_TO_SCHEME[publicKey.flag() as SignatureFlag];
150
+
151
+ return {
152
+ pubKey: { [scheme]: Array.from(publicKey.toRawBytes()) } as PublicKeyEnum,
153
+ weight,
154
+ };
155
+ }),
156
+ threshold,
157
+ });
158
+ }
159
+
160
+ /**
161
+ * Checks if two MultiSig public keys are equal
162
+ */
163
+ override equals(publicKey: MultiSigPublicKey): boolean {
164
+ return super.equals(publicKey);
165
+ }
166
+
167
+ /**
168
+ * Return the byte array representation of the MultiSig public key
169
+ */
170
+ toRawBytes(): Uint8Array {
171
+ return this.rawBytes;
172
+ }
173
+
174
+ getPublicKeys() {
175
+ return this.publicKeys;
176
+ }
177
+
178
+ getThreshold() {
179
+ return this.multisigPublicKey.threshold;
180
+ }
181
+
182
+ getSigner(...signers: [signer: Signer]) {
183
+ return new MultiSigSigner(this, signers);
184
+ }
185
+
186
+ /**
187
+ * Return the Sui address associated with this MultiSig public key
188
+ */
189
+ override toSuiAddress(): string {
190
+ // max length = 1 flag byte + (max pk size + max weight size (u8)) * max signer size + 2 threshold bytes (u16)
191
+ const maxLength = 1 + (64 + 1) * MAX_SIGNER_IN_MULTISIG + 2;
192
+ const tmp = new Uint8Array(maxLength);
193
+ tmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);
194
+
195
+ tmp.set(bcs.u16().serialize(this.multisigPublicKey.threshold).toBytes(), 1);
196
+ // The initial value 3 ensures that following data will be after the flag byte and threshold bytes
197
+ let i = 3;
198
+ for (const { publicKey, weight } of this.publicKeys) {
199
+ const bytes = publicKey.toSuiBytes();
200
+ tmp.set(bytes, i);
201
+ i += bytes.length;
202
+ tmp.set([weight], i++);
203
+ }
204
+ return normalizeSuiAddress(bytesToHex(blake2b(tmp.slice(0, i), { dkLen: 32 })));
205
+ }
206
+
207
+ /**
208
+ * Return the Sui address associated with this MultiSig public key
209
+ */
210
+ flag(): number {
211
+ return SIGNATURE_SCHEME_TO_FLAG['MultiSig'];
212
+ }
213
+
214
+ /**
215
+ * Verifies that the signature is valid for for the provided message
216
+ */
217
+ async verify(message: Uint8Array, multisigSignature: string): Promise<boolean> {
218
+ // Multisig verification only supports serialized signature
219
+ const parsed = parseSerializedSignature(multisigSignature);
220
+
221
+ if (parsed.signatureScheme !== 'MultiSig') {
222
+ throw new Error('Invalid signature scheme');
223
+ }
224
+
225
+ const { multisig } = parsed;
226
+
227
+ let signatureWeight = 0;
228
+
229
+ if (
230
+ !bytesEqual(
231
+ bcs.MultiSigPublicKey.serialize(this.multisigPublicKey).toBytes(),
232
+ bcs.MultiSigPublicKey.serialize(multisig.multisig_pk).toBytes(),
233
+ )
234
+ ) {
235
+ return false;
236
+ }
237
+
238
+ for (const { publicKey, weight, signature } of parsePartialSignatures(multisig)) {
239
+ if (!(await publicKey.verify(message, signature))) {
240
+ return false;
241
+ }
242
+
243
+ signatureWeight += weight;
244
+ }
245
+
246
+ return signatureWeight >= this.multisigPublicKey.threshold;
247
+ }
248
+
249
+ /**
250
+ * Combines multiple partial signatures into a single multisig, ensuring that each public key signs only once
251
+ * and that all the public keys involved are known and valid, and then serializes multisig into the standard format
252
+ */
253
+ combinePartialSignatures(signatures: string[]): string {
254
+ if (signatures.length > MAX_SIGNER_IN_MULTISIG) {
255
+ throw new Error(`Max number of signatures in a multisig is ${MAX_SIGNER_IN_MULTISIG}`);
256
+ }
257
+
258
+ let bitmap = 0;
259
+ const compressedSignatures: CompressedSignature[] = new Array(signatures.length);
260
+
261
+ for (let i = 0; i < signatures.length; i++) {
262
+ let parsed = parseSerializedSignature(signatures[i]);
263
+ if (parsed.signatureScheme === 'MultiSig') {
264
+ throw new Error('MultiSig is not supported inside MultiSig');
265
+ }
266
+
267
+ let publicKey;
268
+ if (parsed.signatureScheme === 'ZkLogin') {
269
+ publicKey = toZkLoginPublicIdentifier(
270
+ parsed.zkLogin?.addressSeed,
271
+ parsed.zkLogin?.iss,
272
+ ).toRawBytes();
273
+ } else {
274
+ publicKey = parsed.publicKey;
275
+ }
276
+
277
+ compressedSignatures[i] = {
278
+ [parsed.signatureScheme]: Array.from(parsed.signature.map((x: number) => Number(x))),
279
+ } as CompressedSignature;
280
+
281
+ let publicKeyIndex;
282
+ for (let j = 0; j < this.publicKeys.length; j++) {
283
+ if (bytesEqual(publicKey, this.publicKeys[j].publicKey.toRawBytes())) {
284
+ if (bitmap & (1 << j)) {
285
+ throw new Error('Received multiple signatures from the same public key');
286
+ }
287
+
288
+ publicKeyIndex = j;
289
+ break;
290
+ }
291
+ }
292
+
293
+ if (publicKeyIndex === undefined) {
294
+ throw new Error('Received signature from unknown public key');
295
+ }
296
+
297
+ bitmap |= 1 << publicKeyIndex;
298
+ }
299
+
300
+ let multisig: MultiSigStruct = {
301
+ sigs: compressedSignatures,
302
+ bitmap,
303
+ multisig_pk: this.multisigPublicKey,
304
+ };
305
+ const bytes = bcs.MultiSig.serialize(multisig, { maxSize: 8192 }).toBytes();
306
+ let tmp = new Uint8Array(bytes.length + 1);
307
+ tmp.set([SIGNATURE_SCHEME_TO_FLAG['MultiSig']]);
308
+ tmp.set(bytes, 1);
309
+ return toB64(tmp);
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Parse multisig structure into an array of individual signatures: signature scheme, the actual individual signature, public key and its weight.
315
+ */
316
+ export function parsePartialSignatures(
317
+ multisig: MultiSigStruct,
318
+ options: { client?: SuiGraphQLClient } = {},
319
+ ): ParsedPartialMultiSigSignature[] {
320
+ let res: ParsedPartialMultiSigSignature[] = new Array(multisig.sigs.length);
321
+ for (let i = 0; i < multisig.sigs.length; i++) {
322
+ const [signatureScheme, signature] = Object.entries(multisig.sigs[i]).filter(
323
+ ([name]) => name !== '$kind',
324
+ )[0] as [SignatureScheme, number[]];
325
+ const pkIndex = asIndices(multisig.bitmap).at(i)!;
326
+ const pair = multisig.multisig_pk.pk_map[pkIndex];
327
+ const pkBytes = Uint8Array.from(Object.values(pair.pubKey)[0]);
328
+
329
+ if (signatureScheme === 'MultiSig') {
330
+ throw new Error('MultiSig is not supported inside MultiSig');
331
+ }
332
+
333
+ const publicKey = publicKeyFromRawBytes(signatureScheme, pkBytes, options);
334
+
335
+ res[i] = {
336
+ signatureScheme,
337
+ signature: Uint8Array.from(signature),
338
+ publicKey: publicKey,
339
+ weight: pair.weight,
340
+ };
341
+ }
342
+ return res;
343
+ }
344
+
345
+ function asIndices(bitmap: number): Uint8Array {
346
+ if (bitmap < 0 || bitmap > 1024) {
347
+ throw new Error('Invalid bitmap');
348
+ }
349
+ let res: number[] = [];
350
+ for (let i = 0; i < 10; i++) {
351
+ if ((bitmap & (1 << i)) !== 0) {
352
+ res.push(i);
353
+ }
354
+ }
355
+ return Uint8Array.from(res);
356
+ }
@@ -0,0 +1,92 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { toB64 } from '@mysten/bcs';
4
+
5
+ import type { SignatureScheme } from '../cryptography/index.js';
6
+ import { Signer } from '../cryptography/index.js';
7
+ import type { MultiSigPublicKey } from './publickey.js';
8
+
9
+ export class MultiSigSigner extends Signer {
10
+ #pubkey: MultiSigPublicKey;
11
+ #signers: Signer[];
12
+
13
+ constructor(pubkey: MultiSigPublicKey, signers: Signer[] = []) {
14
+ super();
15
+ this.#pubkey = pubkey;
16
+ this.#signers = signers;
17
+
18
+ let uniqueKeys = new Set();
19
+ let combinedWeight = 0;
20
+
21
+ const weights = pubkey.getPublicKeys().map(({ weight, publicKey }) => ({
22
+ weight,
23
+ address: publicKey.toSuiAddress(),
24
+ }));
25
+
26
+ for (let signer of signers) {
27
+ const address = signer.toSuiAddress();
28
+ if (uniqueKeys.has(address)) {
29
+ throw new Error(`Can't create MultiSigSigner with duplicate signers`);
30
+ }
31
+ uniqueKeys.add(address);
32
+
33
+ const weight = weights.find((w) => w.address === address)?.weight;
34
+
35
+ if (!weight) {
36
+ throw new Error(`Signer ${address} is not part of the MultiSig public key`);
37
+ }
38
+
39
+ combinedWeight += weight;
40
+ }
41
+
42
+ if (combinedWeight < pubkey.getThreshold()) {
43
+ throw new Error(`Combined weight of signers is less than threshold`);
44
+ }
45
+ }
46
+
47
+ getKeyScheme(): SignatureScheme {
48
+ return 'MultiSig';
49
+ }
50
+
51
+ getPublicKey(): MultiSigPublicKey {
52
+ return this.#pubkey;
53
+ }
54
+
55
+ sign(_data: Uint8Array): never {
56
+ throw new Error(
57
+ 'MultiSigSigner does not support signing directly. Use signTransaction or signPersonalMessage instead',
58
+ );
59
+ }
60
+
61
+ signData(_data: Uint8Array): never {
62
+ throw new Error(
63
+ 'MultiSigSigner does not support signing directly. Use signTransaction or signPersonalMessage instead',
64
+ );
65
+ }
66
+
67
+ async signTransaction(bytes: Uint8Array) {
68
+ const signature = this.#pubkey.combinePartialSignatures(
69
+ await Promise.all(
70
+ this.#signers.map(async (signer) => (await signer.signTransaction(bytes)).signature),
71
+ ),
72
+ );
73
+
74
+ return {
75
+ signature,
76
+ bytes: toB64(bytes),
77
+ };
78
+ }
79
+
80
+ async signPersonalMessage(bytes: Uint8Array) {
81
+ const signature = this.#pubkey.combinePartialSignatures(
82
+ await Promise.all(
83
+ this.#signers.map(async (signer) => (await signer.signPersonalMessage(bytes)).signature),
84
+ ),
85
+ );
86
+
87
+ return {
88
+ signature,
89
+ bytes: toB64(bytes),
90
+ };
91
+ }
92
+ }