@mysten-incubation/hashi 0.0.1

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 (37) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/dist/bitcoin.d.mts +140 -0
  3. package/dist/bitcoin.mjs +272 -0
  4. package/dist/client.d.mts +318 -0
  5. package/dist/client.mjs +522 -0
  6. package/dist/constants.mjs +60 -0
  7. package/dist/contracts/hashi/bitcoin_state.mjs +28 -0
  8. package/dist/contracts/hashi/committee.mjs +40 -0
  9. package/dist/contracts/hashi/committee_set.mjs +34 -0
  10. package/dist/contracts/hashi/config.mjs +28 -0
  11. package/dist/contracts/hashi/config_value.mjs +21 -0
  12. package/dist/contracts/hashi/deposit.mjs +67 -0
  13. package/dist/contracts/hashi/deposit_queue.mjs +33 -0
  14. package/dist/contracts/hashi/deps/sui/bag.mjs +42 -0
  15. package/dist/contracts/hashi/deps/sui/balance.mjs +20 -0
  16. package/dist/contracts/hashi/deps/sui/group_ops.mjs +16 -0
  17. package/dist/contracts/hashi/deps/sui/object_bag.mjs +25 -0
  18. package/dist/contracts/hashi/deps/sui/package.mjs +26 -0
  19. package/dist/contracts/hashi/deps/sui/table.mjs +37 -0
  20. package/dist/contracts/hashi/deps/sui/vec_map.mjs +36 -0
  21. package/dist/contracts/hashi/deps/sui/vec_set.mjs +25 -0
  22. package/dist/contracts/hashi/hashi.mjs +29 -0
  23. package/dist/contracts/hashi/proposals.mjs +18 -0
  24. package/dist/contracts/hashi/treasury.mjs +28 -0
  25. package/dist/contracts/hashi/utxo.mjs +56 -0
  26. package/dist/contracts/hashi/utxo_pool.mjs +35 -0
  27. package/dist/contracts/hashi/withdraw.mjs +91 -0
  28. package/dist/contracts/hashi/withdrawal_queue.mjs +131 -0
  29. package/dist/contracts/utils/index.d.mts +8 -0
  30. package/dist/contracts/utils/index.mjs +118 -0
  31. package/dist/errors.d.mts +118 -0
  32. package/dist/errors.mjs +118 -0
  33. package/dist/index.d.mts +5 -0
  34. package/dist/index.mjs +5 -0
  35. package/dist/types.d.mts +137 -0
  36. package/dist/util.mjs +50 -0
  37. package/package.json +64 -0
package/dist/util.mjs ADDED
@@ -0,0 +1,50 @@
1
+ import { HashiConfigError, InvalidParamsError } from "./errors.mjs";
2
+
3
+ //#region src/util.ts
4
+ /** 0x-prefixed 32-byte hex (66 chars). Matches Sui addresses and Bitcoin txids. */
5
+ const HEX32_RE = /^0x[0-9a-fA-F]{64}$/;
6
+ /**
7
+ * Guards that `value` is a 0x-prefixed 32-byte hex string, throwing
8
+ * `InvalidParamsError` otherwise. `fieldName` is interpolated into
9
+ * the error message so callers can tell which deposit parameter failed.
10
+ */
11
+ function assertHex32(value, fieldName) {
12
+ if (typeof value !== "string" || !HEX32_RE.test(value)) throw new InvalidParamsError({
13
+ reason: `\`${fieldName}\` must be a 0x-prefixed 32-byte hex string`,
14
+ detail: `got ${JSON.stringify(value)}`
15
+ });
16
+ }
17
+ /**
18
+ * Reverse the 32 bytes of a Bitcoin txid between display order (the
19
+ * big-endian form shown by mempool.space, blockstream.info, and
20
+ * `bitcoin-cli`) and internal byte order (the little-endian form Bitcoin
21
+ * Core stores natively, and the form `bitcoin::Txid` parses to).
22
+ *
23
+ * The Hashi committee verifier reads `Utxo.txid` from on-chain state as a
24
+ * `bitcoin::Txid`, so deposits must record the txid in **internal byte
25
+ * order**. End users hold display-order txids (everything user-facing
26
+ * shows that), so the SDK accepts display-order as input and reverses
27
+ * here before recording.
28
+ */
29
+ function reverseTxidBytes(txid) {
30
+ assertHex32(txid, "txid");
31
+ const hex = txid.slice(2);
32
+ let reversed = "0x";
33
+ for (let i = hex.length - 2; i >= 0; i -= 2) reversed += hex.slice(i, i + 2);
34
+ return reversed;
35
+ }
36
+ /**
37
+ * Find a VecMap entry by key and narrow its `Value` variant. Discriminating
38
+ * on `$kind` lets TypeScript narrow the returned payload — callers get the
39
+ * variant-specific fields (e.g. `.U64: string`, `.Bool: boolean`) without
40
+ * any manual type assertions.
41
+ */
42
+ function entry(contents, key, expectedVariant) {
43
+ const e = contents.find((c) => c.key === key);
44
+ if (!e) throw HashiConfigError.missing(key, expectedVariant);
45
+ if (e.value.$kind !== expectedVariant) throw HashiConfigError.wrongVariant(key, expectedVariant, e.value.$kind);
46
+ return e.value;
47
+ }
48
+
49
+ //#endregion
50
+ export { assertHex32, entry, reverseTxidBytes };
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@mysten-incubation/hashi",
3
+ "version": "0.0.1",
4
+ "description": "TypeScript SDK for the Hashi Sui Move smart contracts",
5
+ "license": "Apache-2.0",
6
+ "author": "Mysten Labs <build@mystenlabs.com>",
7
+ "type": "module",
8
+ "main": "./dist/index.mjs",
9
+ "types": "./dist/index.d.mts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.mts",
13
+ "import": "./dist/index.mjs"
14
+ }
15
+ },
16
+ "sideEffects": false,
17
+ "files": [
18
+ "CHANGELOG.md",
19
+ "LICENSE",
20
+ "dist"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/MystenLabs/hashi-ts-sdk.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/MystenLabs/hashi-ts-sdk/issues/new"
28
+ },
29
+ "homepage": "https://github.com/MystenLabs/hashi-ts-sdk#readme",
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "keywords": [
34
+ "sui",
35
+ "hashi",
36
+ "bitcoin",
37
+ "btc",
38
+ "sdk",
39
+ "mysten"
40
+ ],
41
+ "scripts": {
42
+ "build": "rm -rf dist && tsc --noEmit && tsdown",
43
+ "test": "vitest --project=unit",
44
+ "test:integration": "vitest run --project=integration",
45
+ "coverage": "vitest run --project=unit --coverage",
46
+ "codegen": "sui-ts-codegen generate",
47
+ "format": "prettier --write \"**/*.{ts,json,md}\""
48
+ },
49
+ "peerDependencies": {
50
+ "@mysten/sui": "^2.14.1"
51
+ },
52
+ "devDependencies": {
53
+ "@mysten/codegen": "^0.8.3",
54
+ "@mysten/sui": "^2.14.1",
55
+ "@types/node": "^25.6.0",
56
+ "@vitest/coverage-v8": "^4.1.5",
57
+ "vitest": "^4.1.5"
58
+ },
59
+ "dependencies": {
60
+ "@noble/curves": "^2.0.1",
61
+ "@noble/hashes": "^2.0.1",
62
+ "@scure/base": "^2.0.0"
63
+ }
64
+ }