@lerna-labs/hydra-sdk 1.0.0-beta.14 → 1.0.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -126,7 +126,7 @@ const chunks = chunkString("abcdef", 2); // ["ab", "cd", "ef"]
126
126
  |--------|-------------|
127
127
  | `getAdmin()` | Create a `MeshWallet` from env-configured signing key |
128
128
  | `createMultisigAddress(addr1, addr2, networkId?, scriptType?)` | Build a multisig address from two participant addresses |
129
- | `createNativeScript(addr, networkId?, scriptType?, invalidBefore?, invalidHereafter?)` | Build a native script address with optional time bounds |
129
+ | `createNativeScript(addr, opts?)` | Build a native script policy bare `sig` by default, or time-bound `all:[sig, before]` when `opts.invalidHereafter` is set |
130
130
  | `getUtxoSet()` | Fetch all UTxOs in the Hydra Head |
131
131
  | `queryUtxoByAddress(address)` | Fetch UTxOs for a specific address |
132
132
  | `submitTx(endpoint, payload, id)` | Submit a signed transaction to the Hydra node |
@@ -5,7 +5,10 @@ import { MeshWallet } from '@meshsdk/core';
5
5
  * Reads the Cardano signing key from `HYDRA_ADMIN_KEY_FILE` (preferred)
6
6
  * or falls back to `HYDRA_ADMIN_CARDANO_PK`. Network is selected via `HYDRA_NETWORK`.
7
7
  *
8
+ * @param blockfrostProjectId - Optional Blockfrost project ID. When provided, the wallet
9
+ * is configured with a Blockfrost fetcher and submitter for L1 operations (e.g. preparing
10
+ * the Hydra head, querying UTxOs, submitting commit transactions).
8
11
  * @returns An initialized MeshWallet ready for signing transactions.
9
12
  * @throws If no signing key is available or the wallet fails to initialize.
10
13
  */
11
- export declare function getAdmin(): Promise<MeshWallet>;
14
+ export declare function getAdmin(blockfrostProjectId?: string): Promise<MeshWallet>;
@@ -1,5 +1,5 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import { MeshWallet } from '@meshsdk/core';
2
+ import { BlockfrostProvider, MeshWallet } from '@meshsdk/core';
3
3
  import { optionalEnv } from '../config.js';
4
4
  /**
5
5
  * Create and initialize a MeshWallet for the Hydra head admin.
@@ -7,10 +7,13 @@ import { optionalEnv } from '../config.js';
7
7
  * Reads the Cardano signing key from `HYDRA_ADMIN_KEY_FILE` (preferred)
8
8
  * or falls back to `HYDRA_ADMIN_CARDANO_PK`. Network is selected via `HYDRA_NETWORK`.
9
9
  *
10
+ * @param blockfrostProjectId - Optional Blockfrost project ID. When provided, the wallet
11
+ * is configured with a Blockfrost fetcher and submitter for L1 operations (e.g. preparing
12
+ * the Hydra head, querying UTxOs, submitting commit transactions).
10
13
  * @returns An initialized MeshWallet ready for signing transactions.
11
14
  * @throws If no signing key is available or the wallet fails to initialize.
12
15
  */
13
- export async function getAdmin() {
16
+ export async function getAdmin(blockfrostProjectId) {
14
17
  let keyCborHex = null;
15
18
  // Preferred: read the instance's cardano.sk file directly (no secrets in .env)
16
19
  const keyFile = process.env.HYDRA_ADMIN_KEY_FILE;
@@ -32,13 +35,19 @@ export async function getAdmin() {
32
35
  else if (networkId > 1) {
33
36
  networkId = 1;
34
37
  }
35
- const wallet = new MeshWallet({
38
+ const walletOptions = {
36
39
  networkId: networkId,
37
40
  key: {
38
41
  type: 'cli',
39
42
  payment: keyCborHex,
40
43
  },
41
- });
44
+ };
45
+ if (blockfrostProjectId) {
46
+ const blockfrost = new BlockfrostProvider(blockfrostProjectId);
47
+ walletOptions.fetcher = blockfrost;
48
+ walletOptions.submitter = blockfrost;
49
+ }
50
+ const wallet = new MeshWallet(walletOptions);
42
51
  await wallet.init();
43
52
  if (!wallet.addresses.enterpriseAddressBech32) {
44
53
  throw new Error('Wallet failed to initialize!');
@@ -15,14 +15,22 @@ export declare function createMultisigAddress(address1: string, address2: string
15
15
  /**
16
16
  * Create a native script policy for minting tokens.
17
17
  *
18
- * @param address1 - Address (bech32) whose key hash is the required signer.
19
- * @param networkId - `0` for testnet, `1` for mainnet.
20
- * @param scriptType - `"any"` or `"all"` when combined with time-lock scripts.
21
- * @param invalidBefore - Optional slot number before which the script is invalid.
22
- * @param invalidHereafter - Optional slot number after which the script is invalid.
18
+ * Without options, produces a bare `sig(keyHash)` script suitable for
19
+ * in-head voter tokens that must remain burnable by the admin.
20
+ *
21
+ * When `invalidHereafter` is provided, produces a compound time-bound
22
+ * script: `all: [sig(keyHash), before(slot)]` each ballot gets its
23
+ * own time-bound policy.
24
+ *
25
+ * @param address - Address (bech32) whose key hash is the required signer.
26
+ * @param opts.invalidHereafter - Slot after which minting is no longer possible.
27
+ * @param opts.networkId - `0` for testnet (default), `1` for mainnet.
23
28
  * @returns The script address, serialized CBOR, and script hash.
24
29
  */
25
- export declare function createNativeScript(address1: string, networkId?: number, scriptType?: 'any' | 'all', invalidBefore?: number | null, invalidHereafter?: number | null): {
30
+ export declare function createNativeScript(address: string, opts?: {
31
+ invalidHereafter?: number;
32
+ networkId?: number;
33
+ }): {
26
34
  address: string;
27
35
  scriptCbor?: string;
28
36
  scriptHash?: string;
@@ -31,37 +31,29 @@ export function createMultisigAddress(address1, address2, networkId = 0, scriptT
31
31
  /**
32
32
  * Create a native script policy for minting tokens.
33
33
  *
34
- * @param address1 - Address (bech32) whose key hash is the required signer.
35
- * @param networkId - `0` for testnet, `1` for mainnet.
36
- * @param scriptType - `"any"` or `"all"` when combined with time-lock scripts.
37
- * @param invalidBefore - Optional slot number before which the script is invalid.
38
- * @param invalidHereafter - Optional slot number after which the script is invalid.
34
+ * Without options, produces a bare `sig(keyHash)` script suitable for
35
+ * in-head voter tokens that must remain burnable by the admin.
36
+ *
37
+ * When `invalidHereafter` is provided, produces a compound time-bound
38
+ * script: `all: [sig(keyHash), before(slot)]` each ballot gets its
39
+ * own time-bound policy.
40
+ *
41
+ * @param address - Address (bech32) whose key hash is the required signer.
42
+ * @param opts.invalidHereafter - Slot after which minting is no longer possible.
43
+ * @param opts.networkId - `0` for testnet (default), `1` for mainnet.
39
44
  * @returns The script address, serialized CBOR, and script hash.
40
45
  */
41
- export function createNativeScript(address1, networkId = 0, scriptType = 'all', invalidBefore = null, invalidHereafter = null) {
42
- const keyHash = deserializeAddress(address1).pubKeyHash;
43
- const script = {
44
- type: scriptType,
45
- scripts: [
46
- {
47
- type: 'sig',
48
- keyHash,
49
- },
50
- ],
51
- };
52
- if (invalidBefore) {
53
- script.scripts.push({
54
- type: 'after',
55
- slot: invalidBefore.toString(),
56
- });
57
- }
58
- if (invalidHereafter) {
59
- script.scripts.push({
60
- type: 'before',
61
- slot: invalidHereafter.toString(),
62
- });
63
- }
64
- const { address, scriptCbor } = serializeNativeScript(script, undefined, networkId);
46
+ export function createNativeScript(address, opts) {
47
+ const networkId = opts?.networkId ?? 0;
48
+ const keyHash = deserializeAddress(address).pubKeyHash;
49
+ const sigScript = { type: 'sig', keyHash };
50
+ const script = opts?.invalidHereafter != null
51
+ ? {
52
+ type: 'all',
53
+ scripts: [sigScript, { type: 'before', slot: opts.invalidHereafter.toString() }],
54
+ }
55
+ : sigScript;
56
+ const { address: scriptAddress, scriptCbor } = serializeNativeScript(script, undefined, networkId);
65
57
  const scriptHash = scriptCbor != null ? resolveScriptHash(scriptCbor) : undefined;
66
- return { address, scriptCbor, scriptHash };
58
+ return { address: scriptAddress, scriptCbor, scriptHash };
67
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lerna-labs/hydra-sdk",
3
- "version": "1.0.0-beta.14",
3
+ "version": "1.0.0-beta.16",
4
4
  "description": "TypeScript SDK for managing Cardano Hydra Heads — lifecycle, UTxO queries, wallet management, transaction submission, and signature verification",
5
5
  "keywords": [
6
6
  "cardano",