@sig-net/midnight-contract-deploy 0.21.0-rc.9 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,6 +21,9 @@ Everything is read from the environment:
21
21
  | `NETWORK_ID` | Target network: `undeployed` (local stack, the default), `stagenet`, `preview`, `preprod` or `mainnet`. Selects the default endpoints. |
22
22
  | `MIDNIGHT_NODE_URL`, `MIDNIGHT_NODE_INDEXER_URL`, `MIDNIGHT_NODE_INDEXER_WS_URL`, `MIDNIGHT_NODE_PROOF_SERVER_URL` | Optional per-endpoint overrides of the network defaults. |
23
23
  | `DEPLOYER_SEED` | The deploying wallet's seed (hex or mnemonic). On the local stack it defaults to the pre-funded genesis mint wallet. |
24
+ | `MIDNIGHT_SIGNET_CONTRACT_ADDRESS` | Optional on a deployed network: the signet singleton a requester contract seals at deploy. `resolveSignetContractAddress` takes the singleton `@sig-net/midnight` publishes for the network when it is unset, and refuses a set value that disagrees with it. The local stack publishes none, so there it names the singleton you deployed. |
25
+ | `MPC_SECP256K1_PUBKEY` | Optional on a deployed network: the MPC root public key a requester's derived accounts start from, in SEC1 hex or NEAR `secp256k1:<base58>` form. `resolveMpcRootPublicKey` takes the key `@sig-net/midnight` publishes for the network when it is unset, refuses a set value that disagrees with it, and returns `0x04…` uncompressed hex either way. |
26
+ | `MIDNIGHT_FAUCET_URL` | The faucet named in the unfunded-wallet hint. Built in per network: stagenet `https://faucet.stagenet.shielded.tools`, preview `https://midnight-tmnight-preview.nethermind.dev`, preprod `https://midnight-tmnight-preprod.nethermind.dev`. Set it to override one of those, or to name a faucet for a network without one. |
24
27
 
25
28
  ## Usage
26
29
 
@@ -32,6 +35,8 @@ const { contractAddress, txId } = await deploySignetContract(process.env);
32
35
 
33
36
  The generic plumbing (network config, wallets, funding, transaction submission) is exported from the package root as well, for deploy scripts of other Compact contracts.
34
37
 
38
+ A pipeline that touches several wallets, or one wallet several times, holds them in a `WalletRegistry`: the first request for a seed builds, starts and fully syncs its facade (on a deployed network a fresh facade scans the chain from nothing, and the sync logs a heartbeat with each sub-wallet's position every ten seconds), every later request returns the same running facade, and `close()` stops them all once. `deploySignetContract(env, wallets)` and the funding primitives (`assertRootFunded`, `readAccountFunding`, `fundChildFromRoot`) take the registry. Without one, `deploySignetContract` opens a private registry for its single wallet and closes it after.
39
+
35
40
  ## Deploying from CI
36
41
 
37
42
  The [sig-net/midnight-integration](https://github.com/sig-net/midnight-integration) repository deploys the singleton through its manually dispatched `deploy` workflow, which picks a network and a release tag and runs this flow on a runner with a local proof server.
@@ -42,7 +47,7 @@ The [sig-net/midnight-integration](https://github.com/sig-net/midnight-integrati
42
47
 
43
48
  ## Documentation
44
49
 
45
- The deployed contract is the singleton of the [sign bidirectional flow](https://github.com/sig-net/midnight-integration/blob/main/README.md#sign-bidirectional-flow), documented in the [sig-net/midnight-integration README](https://github.com/sig-net/midnight-integration/blob/main/README.md).
50
+ The deployed contract is the singleton of the [sign bidirectional flow](https://github.com/sig-net/midnight-integration/blob/main/README.md#sign-bidirectional-protocol-flow), documented in the [sig-net/midnight-integration README](https://github.com/sig-net/midnight-integration/blob/main/README.md).
46
51
 
47
52
  ## Related packages
48
53
 
@@ -1,4 +1,4 @@
1
- import { type TransactionIdentifier } from "./plumbing/wallet.ts";
1
+ import { type TransactionIdentifier, WalletRegistry } from "./plumbing/wallet.ts";
2
2
  /** The outcome of a successful signet-contract deployment. */
3
3
  export interface SignetContractDeployment {
4
4
  /** Address of the deployed signet contract on Midnight. */
@@ -12,15 +12,19 @@ export interface SignetContractDeployment {
12
12
  * logged to the console. The contract takes no constructor arguments. Any
13
13
  * funded wallet can deploy, and nothing about the deployer is sealed. The wallet
14
14
  * needs NIGHT only: {@link ensureFeeReady} registers it for dust generation
15
- * and waits for the first spendable DUST when the wallet has none yet.
15
+ * and waits for the deploy transaction's fee in spendable DUST when the
16
+ * wallet holds less.
16
17
  *
17
18
  * @param env - Environment map providing `DEPLOYER_SEED` and the shared
18
19
  * Midnight node configuration (see `getMidnightNodeConfig`).
20
+ * @param wallets - A registry to take the deployer wallet from, when the caller
21
+ * keeps wallets open across steps. Without one, a private registry is opened
22
+ * for this deploy and closed after it.
19
23
  * @returns The deployed contract address and deploy transaction id.
20
24
  * @throws {WalletUnfundedError} If the deployer wallet holds neither NIGHT
21
25
  * nor DUST: the error carries the wallet's NIGHT receive address to fund.
22
- * @throws {Error} If no spendable DUST appears after registering the wallet's
23
- * NIGHT, or submission fails.
26
+ * @throws {Error} If the deploy's fee does not generate in spendable DUST after
27
+ * registering the wallet's NIGHT, or submission fails.
24
28
  */
25
- export declare function deploySignetContract(env?: Record<string, string | undefined>): Promise<SignetContractDeployment>;
29
+ export declare function deploySignetContract(env?: Record<string, string | undefined>, wallets?: WalletRegistry): Promise<SignetContractDeployment>;
26
30
  //# sourceMappingURL=deploy-signet-contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deploy-signet-contract.d.ts","sourceRoot":"","sources":["../src/deploy-signet-contract.ts"],"names":[],"mappings":"AAWA,OAAO,EAGL,KAAK,qBAAqB,EAE3B,MAAM,sBAAsB,CAAC;AAM9B,8DAA8D;AAC9D,MAAM,WAAW,wBAAwB;IACvC,2DAA2D;IAC3D,eAAe,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,IAAI,EAAE,qBAAqB,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,OAAO,CAAC,wBAAwB,CAAC,CAqCnC"}
1
+ {"version":3,"file":"deploy-signet-contract.d.ts","sourceRoot":"","sources":["../src/deploy-signet-contract.ts"],"names":[],"mappings":"AAWA,OAAO,EAGL,KAAK,qBAAqB,EAC1B,cAAc,EACf,MAAM,sBAAsB,CAAC;AAM9B,8DAA8D;AAC9D,MAAM,WAAW,wBAAwB;IACvC,2DAA2D;IAC3D,eAAe,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,IAAI,EAAE,qBAAqB,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,EACrD,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,wBAAwB,CAAC,CAyCnC"}
@@ -8,7 +8,7 @@
8
8
  import { buildDeployTransaction, getDeployConfig } from "./plumbing/deploy.js";
9
9
  import { ensureFeeReady } from "./plumbing/funding.js";
10
10
  import { getFaucetUrl } from "./plumbing/midnight-node-config.js";
11
- import { deriveAccountKeys, submitUnprovenTransaction, withSyncedWalletFacade, } from "./plumbing/wallet.js";
11
+ import { estimateUnprovenTransactionFee, submitUnprovenTransaction, WalletRegistry, } from "./plumbing/wallet.js";
12
12
  import { createSignetContractPrivateState, signetContractCompiledContract, } from "./signet-contract-binding.js";
13
13
  /**
14
14
  * Deploy the signet contract: read config from `env`, build and prove the
@@ -16,30 +16,43 @@ import { createSignetContractPrivateState, signetContractCompiledContract, } fro
16
16
  * logged to the console. The contract takes no constructor arguments. Any
17
17
  * funded wallet can deploy, and nothing about the deployer is sealed. The wallet
18
18
  * needs NIGHT only: {@link ensureFeeReady} registers it for dust generation
19
- * and waits for the first spendable DUST when the wallet has none yet.
19
+ * and waits for the deploy transaction's fee in spendable DUST when the
20
+ * wallet holds less.
20
21
  *
21
22
  * @param env - Environment map providing `DEPLOYER_SEED` and the shared
22
23
  * Midnight node configuration (see `getMidnightNodeConfig`).
24
+ * @param wallets - A registry to take the deployer wallet from, when the caller
25
+ * keeps wallets open across steps. Without one, a private registry is opened
26
+ * for this deploy and closed after it.
23
27
  * @returns The deployed contract address and deploy transaction id.
24
28
  * @throws {WalletUnfundedError} If the deployer wallet holds neither NIGHT
25
29
  * nor DUST: the error carries the wallet's NIGHT receive address to fund.
26
- * @throws {Error} If no spendable DUST appears after registering the wallet's
27
- * NIGHT, or submission fails.
30
+ * @throws {Error} If the deploy's fee does not generate in spendable DUST after
31
+ * registering the wallet's NIGHT, or submission fails.
28
32
  */
29
- export async function deploySignetContract(env = process.env) {
33
+ export async function deploySignetContract(env = process.env, wallets) {
30
34
  const deployConfig = getDeployConfig(env);
31
35
  const { networkId } = deployConfig.midnightNodeConfig;
32
- const accountKeys = deriveAccountKeys(deployConfig.deployerSeed, networkId);
36
+ const registry = wallets ?? new WalletRegistry(deployConfig.midnightNodeConfig);
33
37
  console.log(`deploying signet-contract to ${networkId} (${deployConfig.midnightNodeConfig.nodeUrl})`);
34
- const { contractAddress, txId } = await withSyncedWalletFacade(accountKeys, deployConfig.midnightNodeConfig, async (facade, state) => {
35
- await ensureFeeReady(facade, accountKeys, state, networkId, getFaucetUrl(env, networkId));
36
- const deployTransaction = await buildDeployTransaction(signetContractCompiledContract, networkId, accountKeys.shieldedSecretKeys.coinPublicKey, createSignetContractPrivateState());
38
+ try {
39
+ const { facade, keys } = await registry.wallet(deployConfig.deployerSeed, "deployer");
40
+ const deployTransaction = await buildDeployTransaction(signetContractCompiledContract, networkId, keys.shieldedSecretKeys.coinPublicKey, createSignetContractPrivateState());
37
41
  console.log(`contract address (pre-submit): ${deployTransaction.contractAddress}`);
38
- const submittedTxId = await submitUnprovenTransaction(facade, accountKeys, deployTransaction.serializedTransaction);
39
- return { contractAddress: deployTransaction.contractAddress, txId: submittedTxId };
40
- });
41
- console.log(`submitted deploy tx ${txId}`);
42
- console.log(`deployed signet-contract at ${contractAddress}`);
43
- return { contractAddress, txId };
42
+ // The one transaction this deploy submits, priced before anything is sent.
43
+ const fee = await estimateUnprovenTransactionFee(facade, deployTransaction.serializedTransaction);
44
+ console.log(`fee budget: 1 transaction at about ${String(fee)} DUST`);
45
+ const state = await facade.waitForSyncedState();
46
+ await ensureFeeReady(facade, keys, state, networkId, getFaucetUrl(env, networkId), fee);
47
+ const txId = await submitUnprovenTransaction(facade, keys, deployTransaction.serializedTransaction);
48
+ const { contractAddress } = deployTransaction;
49
+ console.log(`submitted deploy tx ${txId}`);
50
+ console.log(`deployed signet-contract at ${contractAddress}`);
51
+ return { contractAddress, txId };
52
+ }
53
+ finally {
54
+ if (wallets === undefined)
55
+ await registry.close();
56
+ }
44
57
  }
45
58
  //# sourceMappingURL=deploy-signet-contract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"deploy-signet-contract.js","sourceRoot":"","sources":["../src/deploy-signet-contract.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,0EAA0E;AAC1E,0EAA0E;AAC1E,uEAAuE;AACvE,mEAAmE;AACnE,sEAAsE;AACtE,6DAA6D;AAE7D,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EAEzB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,gCAAgC,EAChC,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AAUtC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAG,GAAuC,OAAO,CAAC,GAAG;IAErD,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC,kBAAkB,CAAC;IAEtD,MAAM,WAAW,GAAG,iBAAiB,CAAC,YAAY,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IAE5E,OAAO,CAAC,GAAG,CACT,gCAAgC,SAAS,KAAK,YAAY,CAAC,kBAAkB,CAAC,OAAO,GAAG,CACzF,CAAC;IAEF,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,MAAM,sBAAsB,CAC5D,WAAW,EACX,YA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C,CAAC;QAExF,MAAM,IAAI,GAAG,MAAM,yBAAyB,CAC1C,MAAM,EACN,IAAI,EACJ,iBAAiB,CAAC,qBAAqB,CACxC,CAAC;QACF,MAAM,EAAE,eAAe,EAAE,GAAG,iBAAiB,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,+BAA+B,eAAe,EAAE,CAAC,CAAC;QAC9D,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;IACnC,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,KAAK,SAAS;YAAE,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;IACpD,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from "./deploy-signet-contract.ts";
2
+ export * from "./plumbing/counterparties.ts";
2
3
  export * from "./plumbing/deploy.ts";
3
4
  export * from "./plumbing/env.ts";
5
+ export * from "./plumbing/format-dust.ts";
4
6
  export * from "./plumbing/funding.ts";
5
7
  export * from "./plumbing/midnight-node-config.ts";
6
8
  export * from "./plumbing/network-id.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC"}
package/dist/index.js CHANGED
@@ -5,8 +5,10 @@
5
5
  // build/submit) the flow is built from. The plumbing is generic on purpose —
6
6
  // any contract package's deploy script composes it.
7
7
  export * from "./deploy-signet-contract.js";
8
+ export * from "./plumbing/counterparties.js";
8
9
  export * from "./plumbing/deploy.js";
9
10
  export * from "./plumbing/env.js";
11
+ export * from "./plumbing/format-dust.js";
10
12
  export * from "./plumbing/funding.js";
11
13
  export * from "./plumbing/midnight-node-config.js";
12
14
  export * from "./plumbing/network-id.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2EAA2E;AAC3E,0EAA0E;AAC1E,oEAAoE;AACpE,6EAA6E;AAC7E,oDAAoD;AAEpD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2EAA2E;AAC3E,0EAA0E;AAC1E,oEAAoE;AACpE,6EAA6E;AAC7E,oDAAoD;AAEpD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,53 @@
1
+ /** Which source supplied a resolved counterparty value. */
2
+ export declare enum CounterpartyOrigin {
3
+ /** The environment variable named for it. */
4
+ Environment = "environment",
5
+ /** The value this SDK publishes for the network. */
6
+ Published = "published"
7
+ }
8
+ /** A counterparty value in its canonical spelling, and where it came from. */
9
+ export interface ResolvedCounterparty {
10
+ readonly value: string;
11
+ readonly origin: CounterpartyOrigin;
12
+ }
13
+ /**
14
+ * The signet singleton a requester contract notifies, as 64 lowercase hex
15
+ * digits: `MIDNIGHT_SIGNET_CONTRACT_ADDRESS` when set (it must agree with the
16
+ * singleton the SDK publishes for a deployed network), else that published
17
+ * singleton.
18
+ *
19
+ * @param env - The environment to read `NETWORK_ID` and `MIDNIGHT_SIGNET_CONTRACT_ADDRESS` from.
20
+ * @returns The address and its origin, or undefined when neither source supplies one.
21
+ * @throws {Error} If the variable is malformed or disagrees with the published singleton.
22
+ */
23
+ export declare function findSignetContractAddress(env: Record<string, string | undefined>): ResolvedCounterparty | undefined;
24
+ /**
25
+ * {@link findSignetContractAddress}, failing when neither source supplies one.
26
+ *
27
+ * @param env - The environment to read `NETWORK_ID` and `MIDNIGHT_SIGNET_CONTRACT_ADDRESS` from.
28
+ * @returns The address and its origin.
29
+ * @throws {Error} If the variable is malformed, disagrees with the published singleton, or
30
+ * is unset on a network the SDK publishes no singleton for.
31
+ */
32
+ export declare function resolveSignetContractAddress(env: Record<string, string | undefined>): ResolvedCounterparty;
33
+ /**
34
+ * The MPC root public key every client key derivation starts from, as
35
+ * `0x04…` uncompressed SEC1 hex: `MPC_SECP256K1_PUBKEY` in any spelling
36
+ * `normaliseSecp256k1PublicKey` accepts when set (it must agree with the key
37
+ * the SDK publishes for a deployed network), else that published key.
38
+ *
39
+ * @param env - The environment to read `NETWORK_ID` and `MPC_SECP256K1_PUBKEY` from.
40
+ * @returns The key and its origin, or undefined when neither source supplies one.
41
+ * @throws {Error} If the variable is not a secp256k1 public key or disagrees with the published key.
42
+ */
43
+ export declare function findMpcRootPublicKey(env: Record<string, string | undefined>): ResolvedCounterparty | undefined;
44
+ /**
45
+ * {@link findMpcRootPublicKey}, failing when neither source supplies one.
46
+ *
47
+ * @param env - The environment to read `NETWORK_ID` and `MPC_SECP256K1_PUBKEY` from.
48
+ * @returns The key and its origin.
49
+ * @throws {Error} If the variable is not a secp256k1 public key, disagrees with the published
50
+ * key, or is unset on a network the SDK publishes no key for.
51
+ */
52
+ export declare function resolveMpcRootPublicKey(env: Record<string, string | undefined>): ResolvedCounterparty;
53
+ //# sourceMappingURL=counterparties.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counterparties.d.ts","sourceRoot":"","sources":["../../src/plumbing/counterparties.ts"],"names":[],"mappings":"AAsBA,2DAA2D;AAC3D,oBAAY,kBAAkB;IAC5B,6CAA6C;IAC7C,WAAW,gBAAgB;IAC3B,oDAAoD;IACpD,SAAS,cAAc;CACxB;AAED,8EAA8E;AAC9E,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;CACrC;AA+FD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GACtC,oBAAoB,GAAG,SAAS,CAElC;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GACtC,oBAAoB,CAEtB;AAeD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GACtC,oBAAoB,GAAG,SAAS,CAElC;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GACtC,oBAAoB,CAEtB"}
@@ -0,0 +1,143 @@
1
+ // The two protocol counterparty values a requester contract seals for good:
2
+ // the signet singleton it notifies (a deploy-time constructor argument) and
3
+ // the MPC root public key its derived accounts start from (pinned at
4
+ // initialise). On a deployed network this SDK publishes both, so a deploy
5
+ // needs neither in its environment, and a value that IS set is checked
6
+ // against the published one: a mismatch would seal an address the real MPC
7
+ // never answers or a key it never signs under. The local standalone stack
8
+ // publishes nothing: its setup deploys a singleton and generates a root key
9
+ // per stack, and passes them through the same environment variables.
10
+ import { getMpcRootPublicKey, getSignetContractAddress, normaliseSecp256k1PublicKey, stripHexPrefix, } from "@sig-net/midnight";
11
+ import { envOrUndefined } from "./env.js";
12
+ import { getMidnightNodeConfig } from "./midnight-node-config.js";
13
+ import { deployedNetwork } from "./network-id.js";
14
+ /** Which source supplied a resolved counterparty value. */
15
+ export var CounterpartyOrigin;
16
+ (function (CounterpartyOrigin) {
17
+ /** The environment variable named for it. */
18
+ CounterpartyOrigin["Environment"] = "environment";
19
+ /** The value this SDK publishes for the network. */
20
+ CounterpartyOrigin["Published"] = "published";
21
+ })(CounterpartyOrigin || (CounterpartyOrigin = {}));
22
+ /**
23
+ * The SDK's published value for a network.
24
+ *
25
+ * @param networkId - The network the run resolved.
26
+ * @param lookup - The published-value lookup (`getSignetContractAddress`, `getMpcRootPublicKey`).
27
+ * @returns The value, or undefined for the local stack and for a deployed network the SDK
28
+ * holds no value for yet (the lookup throws there, and "not published yet" is a normal
29
+ * state for a young network).
30
+ */
31
+ function published(networkId, lookup) {
32
+ const network = deployedNetwork(networkId);
33
+ if (network === undefined)
34
+ return undefined;
35
+ try {
36
+ return lookup(network);
37
+ }
38
+ catch {
39
+ return undefined;
40
+ }
41
+ }
42
+ function find(env, spec) {
43
+ const { networkId } = getMidnightNodeConfig(env);
44
+ const supplied = envOrUndefined(env, spec.envVar);
45
+ const fromEnvironment = supplied === undefined ? undefined : spec.canonicalise(supplied);
46
+ const publishedRaw = published(networkId, spec.lookup);
47
+ const fromSdk = publishedRaw === undefined ? undefined : spec.canonicalise(publishedRaw);
48
+ if (fromEnvironment !== undefined && fromSdk !== undefined && fromEnvironment !== fromSdk) {
49
+ throw new Error(`${spec.envVar} (${fromEnvironment}) disagrees with ${spec.noun} the SDK publishes for ` +
50
+ `"${networkId}" (${fromSdk}). ${spec.disagreementConsequence}`);
51
+ }
52
+ if (fromEnvironment !== undefined) {
53
+ return { value: fromEnvironment, origin: CounterpartyOrigin.Environment };
54
+ }
55
+ if (fromSdk !== undefined) {
56
+ return { value: fromSdk, origin: CounterpartyOrigin.Published };
57
+ }
58
+ return undefined;
59
+ }
60
+ function resolve(env, spec) {
61
+ const found = find(env, spec);
62
+ if (found !== undefined)
63
+ return found;
64
+ const { networkId } = getMidnightNodeConfig(env);
65
+ const remedy = deployedNetwork(networkId) === undefined
66
+ ? spec.localStackRemedy
67
+ : `the SDK publishes no ${spec.noun.replace(/^the /, "")} for it yet`;
68
+ throw new Error(`${spec.envVar} is required on "${networkId}": ${remedy}.`);
69
+ }
70
+ const SIGNET_CONTRACT_ADDRESS = {
71
+ envVar: "MIDNIGHT_SIGNET_CONTRACT_ADDRESS",
72
+ noun: "the signet singleton",
73
+ lookup: getSignetContractAddress,
74
+ canonicalise: (value) => {
75
+ const digits = stripHexPrefix(value);
76
+ if (!/^[0-9a-fA-F]{64}$/.test(digits)) {
77
+ throw new Error(`MIDNIGHT_SIGNET_CONTRACT_ADDRESS is not a 32-byte contract address in hex: "${value}"`);
78
+ }
79
+ return digits.toLowerCase();
80
+ },
81
+ disagreementConsequence: "The real MPC answers only the published one, and a requester seals the address at deploy: " +
82
+ "reconcile them before deploying.",
83
+ localStackRemedy: "deploy one with deploySignetContract and set its address",
84
+ };
85
+ /**
86
+ * The signet singleton a requester contract notifies, as 64 lowercase hex
87
+ * digits: `MIDNIGHT_SIGNET_CONTRACT_ADDRESS` when set (it must agree with the
88
+ * singleton the SDK publishes for a deployed network), else that published
89
+ * singleton.
90
+ *
91
+ * @param env - The environment to read `NETWORK_ID` and `MIDNIGHT_SIGNET_CONTRACT_ADDRESS` from.
92
+ * @returns The address and its origin, or undefined when neither source supplies one.
93
+ * @throws {Error} If the variable is malformed or disagrees with the published singleton.
94
+ */
95
+ export function findSignetContractAddress(env) {
96
+ return find(env, SIGNET_CONTRACT_ADDRESS);
97
+ }
98
+ /**
99
+ * {@link findSignetContractAddress}, failing when neither source supplies one.
100
+ *
101
+ * @param env - The environment to read `NETWORK_ID` and `MIDNIGHT_SIGNET_CONTRACT_ADDRESS` from.
102
+ * @returns The address and its origin.
103
+ * @throws {Error} If the variable is malformed, disagrees with the published singleton, or
104
+ * is unset on a network the SDK publishes no singleton for.
105
+ */
106
+ export function resolveSignetContractAddress(env) {
107
+ return resolve(env, SIGNET_CONTRACT_ADDRESS);
108
+ }
109
+ const MPC_ROOT_PUBLIC_KEY = {
110
+ envVar: "MPC_SECP256K1_PUBKEY",
111
+ noun: "the MPC root public key",
112
+ lookup: getMpcRootPublicKey,
113
+ canonicalise: normaliseSecp256k1PublicKey,
114
+ disagreementConsequence: "One of the two is wrong, and the key is sealed into every derived account: reconcile them " +
115
+ "before deploying.",
116
+ localStackRemedy: "set it to the root public key of the MPC facing this stack (a fakenet derives it from its " +
117
+ "MPC_ROOT_KEY)",
118
+ };
119
+ /**
120
+ * The MPC root public key every client key derivation starts from, as
121
+ * `0x04…` uncompressed SEC1 hex: `MPC_SECP256K1_PUBKEY` in any spelling
122
+ * `normaliseSecp256k1PublicKey` accepts when set (it must agree with the key
123
+ * the SDK publishes for a deployed network), else that published key.
124
+ *
125
+ * @param env - The environment to read `NETWORK_ID` and `MPC_SECP256K1_PUBKEY` from.
126
+ * @returns The key and its origin, or undefined when neither source supplies one.
127
+ * @throws {Error} If the variable is not a secp256k1 public key or disagrees with the published key.
128
+ */
129
+ export function findMpcRootPublicKey(env) {
130
+ return find(env, MPC_ROOT_PUBLIC_KEY);
131
+ }
132
+ /**
133
+ * {@link findMpcRootPublicKey}, failing when neither source supplies one.
134
+ *
135
+ * @param env - The environment to read `NETWORK_ID` and `MPC_SECP256K1_PUBKEY` from.
136
+ * @returns The key and its origin.
137
+ * @throws {Error} If the variable is not a secp256k1 public key, disagrees with the published
138
+ * key, or is unset on a network the SDK publishes no key for.
139
+ */
140
+ export function resolveMpcRootPublicKey(env) {
141
+ return resolve(env, MPC_ROOT_PUBLIC_KEY);
142
+ }
143
+ //# sourceMappingURL=counterparties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counterparties.js","sourceRoot":"","sources":["../../src/plumbing/counterparties.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,qEAAqE;AACrE,0EAA0E;AAC1E,uEAAuE;AACvE,2EAA2E;AAC3E,0EAA0E;AAC1E,4EAA4E;AAC5E,qEAAqE;AAErE,OAAO,EAEL,mBAAmB,EACnB,wBAAwB,EACxB,2BAA2B,EAC3B,cAAc,GACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAkB,MAAM,iBAAiB,CAAC;AAElE,2DAA2D;AAC3D,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,6CAA6C;IAC7C,iDAA2B,CAAA;IAC3B,oDAAoD;IACpD,6CAAuB,CAAA;AACzB,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B;AAsBD;;;;;;;;GAQG;AACH,SAAS,SAAS,CAChB,SAAoB,EACpB,MAA4C;IAE5C,MAAM,OAAO,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,S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4B,CAC1C,GAAuC;IAEvC,OAAO,OAAO,CAAC,GAAG,EAAE,uBAAuB,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,mBAAmB,GAAqB;IAC5C,MAAM,EAAE,sBAAsB;IAC9B,IAAI,EAAE,yBAAyB;IAC/B,MAAM,EAAE,mBAAmB;IAC3B,YAAY,EAAE,2BAA2B;IACzC,uBAAuB,EACrB,4FAA4F;QAC5F,mBAAmB;IACrB,gBAAgB,EACd,4FAA4F;QAC5F,eAAe;CAClB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAClC,GAAuC;IAEvC,OAAO,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,GAAuC;IAEvC,OAAO,OAAO,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Format SPECKs as DUST with all 15 decimal places preserved when significant.
3
+ *
4
+ * @param specks - The amount in atomic DUST units.
5
+ * @returns The decimal DUST amount, without a unit suffix.
6
+ */
7
+ export declare function formatDust(specks: bigint): string;
8
+ //# sourceMappingURL=format-dust.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-dust.d.ts","sourceRoot":"","sources":["../../src/plumbing/format-dust.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKjD"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Format SPECKs as DUST with all 15 decimal places preserved when significant.
3
+ *
4
+ * @param specks - The amount in atomic DUST units.
5
+ * @returns The decimal DUST amount, without a unit suffix.
6
+ */
7
+ export function formatDust(specks) {
8
+ const magnitude = (specks < 0n ? -specks : specks).toString().padStart(16, "0");
9
+ let fraction = magnitude.slice(-15);
10
+ while (fraction.endsWith("0"))
11
+ fraction = fraction.slice(0, -1);
12
+ return `${specks < 0n ? "-" : ""}${magnitude.slice(0, -15)}${fraction ? `.${fraction}` : ""}`;
13
+ }
14
+ //# sourceMappingURL=format-dust.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-dust.js","sourceRoot":"","sources":["../../src/plumbing/format-dust.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,MAAM,SAAS,GAAW,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACxF,IAAI,QAAQ,GAAW,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5C,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAChE,OAAO,GAAG,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAChG,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { MidnightNodeConfig } from "./midnight-node-config.ts";
2
2
  import { type NetworkId } from "./network-id.ts";
3
- import { type AccountKeys, type FacadeState, type WalletAddresses, type WalletFacade } from "./wallet.ts";
3
+ import { type AccountKeys, type FacadeState, type WalletAddresses, type WalletFacade, type WalletRegistry } from "./wallet.ts";
4
4
  /** A wallet's synced funding snapshot: its addresses and NIGHT/DUST balances (base units). */
5
5
  export interface AccountFunding {
6
6
  /** The wallet's three bech32m addresses (network-prefixed). */
@@ -20,20 +20,23 @@ export interface AccountFunding {
20
20
  */
21
21
  export declare function deriveWalletAddresses(seed: string, config: MidnightNodeConfig): WalletAddresses;
22
22
  /**
23
- * Sync a wallet and read its funding snapshot (addresses + NIGHT + DUST).
23
+ * Read a wallet's funding snapshot (addresses + NIGHT + DUST) from its synced
24
+ * state, syncing it first if the registry has not opened it yet.
24
25
  *
25
- * @param config - The stack the wallet connects to.
26
+ * @param wallets - The registry holding the wallet.
26
27
  * @param seed - The wallet seed (hex or mnemonic).
28
+ * @param label - The wallet's role name, for the sync log.
27
29
  * @returns The synced {@link AccountFunding}.
28
30
  */
29
- export declare function readAccountFunding(config: MidnightNodeConfig, seed: string): Promise<AccountFunding>;
31
+ export declare function readAccountFunding(wallets: WalletRegistry, seed: string, label: string): Promise<AccountFunding>;
30
32
  /**
31
- * A wallet is fee-ready when it holds NIGHT and that NIGHT has generated spendable dust.
33
+ * A wallet is fee-ready when its spendable DUST covers `minimumDust`.
32
34
  *
33
35
  * @param funding - The wallet's measured funding.
36
+ * @param minimumDust - The spendable DUST that counts as ready, in base units, 1 (any dust at all) by default.
34
37
  * @returns Whether the wallet can pay fees right now.
35
38
  */
36
- export declare function isFeeReady(funding: AccountFunding): boolean;
39
+ export declare function isFeeReady(funding: AccountFunding, minimumDust?: bigint): boolean;
37
40
  /**
38
41
  * A wallet holds no NIGHT and no DUST, so it cannot pay fees until its NIGHT
39
42
  * receive address is funded (on a deployed network, via the network's
@@ -56,10 +59,14 @@ export declare class WalletUnfundedError extends Error {
56
59
  * generation, so every unregistered NIGHT UTXO the wallet holds is registered
57
60
  * here first, whatever its current dust: a faucet top-up or transfer change
58
61
  * arrives unregistered, and leaving it so while older dust lasts would let
59
- * the wallet's dust generation shrink with every spend. Then a wallet with
60
- * spendable dust returns it, and one without waits until its first dust
61
- * appears (a few blocks). The facade must be started and synced, and `state`
62
- * must be its synced state (see `withSyncedWalletFacade` in wallet.ts).
62
+ * the wallet's dust generation shrink with every spend. Then a wallet holding
63
+ * at least `minimumDust` of spendable dust returns it, and one without waits
64
+ * until it does: a few blocks for a fresh registration, longer for a
65
+ * multi-transaction budget. A flow about to submit several transactions
66
+ * passes their total fee as `minimumDust`, so a wallet that cannot cover
67
+ * them stops here with the shortfall named and nothing submitted. The facade
68
+ * must be started and synced, and `state` must be its synced state (see
69
+ * `withSyncedWalletFacade` in wallet.ts).
63
70
  *
64
71
  * @param facade - A started wallet facade for `keys`, which submits the registration.
65
72
  * @param keys - The key material of the same wallet. Its keystore signs the registration.
@@ -67,12 +74,14 @@ export declare class WalletUnfundedError extends Error {
67
74
  * @param networkId - The network the wallet lives on, which prefixes the
68
75
  * NIGHT receive address the no-NIGHT error prints for faucet funding.
69
76
  * @param faucetUrl - The network's faucet for the no-NIGHT hint, when one is known.
70
- * @returns The wallet's spendable DUST balance, always positive.
71
- * @throws {WalletUnfundedError} If the wallet holds neither NIGHT nor DUST.
72
- * @throws {Error} If no dust appears in time after registration (see
77
+ * @param minimumDust - The spendable DUST to require, in base units, 1 (any dust at all) by default.
78
+ * @param timeoutMs - Spendable DUST wait deadline in milliseconds, after registration.
79
+ * @returns The wallet's spendable DUST balance, at least `minimumDust`.
80
+ * @throws {WalletUnfundedError} If the wallet holds no NIGHT and less than `minimumDust` of DUST.
81
+ * @throws {Error} If the dust stays below `minimumDust` for the wait's timeout (see
73
82
  * {@link waitForSpendableDust}).
74
83
  */
75
- export declare function ensureFeeReady(facade: WalletFacade, keys: AccountKeys, state: FacadeState, networkId: NetworkId, faucetUrl?: string): Promise<bigint>;
84
+ export declare function ensureFeeReady(facade: WalletFacade, keys: AccountKeys, state: FacadeState, networkId: NetworkId, faucetUrl?: string, minimumDust?: bigint, timeoutMs?: number): Promise<bigint>;
76
85
  /**
77
86
  * Ensure the root wallet is fee-ready, returning its snapshot. Root holds no
78
87
  * NIGHT on a deployed network before faucet funding, so this throws
@@ -84,7 +93,7 @@ export declare function ensureFeeReady(facade: WalletFacade, keys: AccountKeys,
84
93
  * {@link ensureFeeReady}: a faucet-funded root needs its NIGHT registered for
85
94
  * dust generation before it holds any spendable DUST.
86
95
  *
87
- * @param config - The stack the root wallet connects to.
96
+ * @param wallets - The registry holding the root wallet.
88
97
  * @param rootSeed - The root wallet seed.
89
98
  * @param faucetUrl - The network's faucet URL for the underfunded message.
90
99
  * @returns The root's fee-ready funding snapshot.
@@ -93,20 +102,21 @@ export declare function ensureFeeReady(facade: WalletFacade, keys: AccountKeys,
93
102
  * {@link waitForSpendableDust}): root is funded but not yet fee-ready, so
94
103
  * this is a plain error, not a funding stop.
95
104
  */
96
- export declare function assertRootFunded(config: MidnightNodeConfig, rootSeed: string, faucetUrl: string | undefined): Promise<AccountFunding>;
105
+ export declare function assertRootFunded(wallets: WalletRegistry, rootSeed: string, faucetUrl: string | undefined): Promise<AccountFunding>;
97
106
  /**
98
107
  * Bring one child wallet to fee-ready by topping it up from root: if it holds
99
108
  * no NIGHT, transfer `amount` from root and wait for the child to see it, then
100
109
  * finish through {@link ensureFeeReady}. A child that already holds NIGHT but
101
- * no dust yet is only registered and waited on (no transfer). Call only for a
102
- * child that is not already fee-ready.
110
+ * no dust yet is registered and waited on. A sufficient DUST balance returns immediately.
103
111
  *
104
- * @param config - The stack both wallets connect to.
112
+ * @param wallets - The registry holding both wallets.
105
113
  * @param rootSeed - The funding wallet's seed.
106
114
  * @param childSeed - The child wallet's seed.
115
+ * @param childLabel - The child's role name, for the sync log.
107
116
  * @param amount - NIGHT to transfer when the child holds none, in base units.
117
+ * @param minimumDust - Required spendable DUST in SPECKs.
108
118
  * @returns The child's post-funding snapshot.
109
119
  * @throws {Error} If root cannot cover the transfer, or dust never appears in time.
110
120
  */
111
- export declare function fundChildFromRoot(config: MidnightNodeConfig, rootSeed: string, childSeed: string, amount: bigint): Promise<AccountFunding>;
121
+ export declare function fundChildFromRoot(wallets: WalletRegistry, rootSeed: string, childSeed: string, childLabel: string, amount: bigint, minimumDust?: bigint): Promise<AccountFunding>;
112
122
  //# sourceMappingURL=funding.d.ts.map
@@ -1 +1 @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