@sig-net/midnight-contract-deploy 0.0.3 → 0.0.5
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 +41 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plumbing/deploy.d.ts +21 -4
- package/dist/plumbing/deploy.d.ts.map +1 -1
- package/dist/plumbing/deploy.js +69 -8
- package/dist/plumbing/deploy.js.map +1 -1
- package/dist/plumbing/funding.d.ts +76 -0
- package/dist/plumbing/funding.d.ts.map +1 -0
- package/dist/plumbing/funding.js +153 -0
- package/dist/plumbing/funding.js.map +1 -0
- package/dist/plumbing/midnight-node-config.d.ts +19 -2
- package/dist/plumbing/midnight-node-config.d.ts.map +1 -1
- package/dist/plumbing/midnight-node-config.js +60 -3
- package/dist/plumbing/midnight-node-config.js.map +1 -1
- package/dist/plumbing/network-id.d.ts +12 -1
- package/dist/plumbing/network-id.d.ts.map +1 -1
- package/dist/plumbing/network-id.js +14 -0
- package/dist/plumbing/network-id.js.map +1 -1
- package/dist/plumbing/seed.d.ts +10 -1
- package/dist/plumbing/seed.d.ts.map +1 -1
- package/dist/plumbing/seed.js +13 -1
- package/dist/plumbing/seed.js.map +1 -1
- package/dist/plumbing/wallet.d.ts +18 -0
- package/dist/plumbing/wallet.d.ts.map +1 -1
- package/dist/plumbing/wallet.js +29 -1
- package/dist/plumbing/wallet.js.map +1 -1
- package/package.json +11 -6
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @sig-net/midnight-contract-deploy
|
|
2
|
+
|
|
3
|
+
Deploy tooling for the central [Sig Network](https://sig.network) signet contract on the [Midnight blockchain](https://midnight.network), self-contained for npm:
|
|
4
|
+
|
|
5
|
+
- **The operator deploy flow** (`deploySignetContract`): builds, balances, proves and submits the signet contract's deploy transaction through a synced wallet, using the compiled assets shipped in [`@sig-net/midnight-contract`](https://www.npmjs.com/package/@sig-net/midnight-contract).
|
|
6
|
+
- **The Node binding** of `@sig-net/midnight-contract` to its compiled assets (zk config, private state).
|
|
7
|
+
- **Generic deploy/wallet plumbing** any Compact contract's deploy script composes: network config, seed parsing and key derivation, the wallet facade lifecycle, funding primitives (a root wallet funds role wallets and registers NIGHT for dust generation), and unproven-transaction build/submit.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @sig-net/midnight-contract-deploy
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Configuration
|
|
16
|
+
|
|
17
|
+
Everything is read from the environment:
|
|
18
|
+
|
|
19
|
+
| Variable | Purpose |
|
|
20
|
+
|---|---|
|
|
21
|
+
| `NETWORK_ID` | Target network: `undeployed` (local stack, the default), `stagenet`, `preview`, `preprod` or `mainnet`. Selects the default endpoints. |
|
|
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
|
+
| `DEPLOYER_SEED` | The deploying wallet's seed (hex or mnemonic). On the local stack it defaults to the pre-funded genesis mint wallet. |
|
|
24
|
+
| `MPC_JUBJUB_PK` | The MPC attestation key, as `x,y` (decimal or 0x-hex field coordinates). The contract seals its hash at deploy time. |
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { deploySignetContract } from "@sig-net/midnight-contract-deploy";
|
|
30
|
+
|
|
31
|
+
const { contractAddress, txId } = await deploySignetContract(process.env);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The generic plumbing (network config, wallets, funding, transaction submission) is exported from the package root as well, for deploy scripts of other Compact contracts.
|
|
35
|
+
|
|
36
|
+
## Related packages
|
|
37
|
+
|
|
38
|
+
- [`@sig-net/midnight-contract`](https://www.npmjs.com/package/@sig-net/midnight-contract): the contract this package deploys.
|
|
39
|
+
- [`@sig-net/midnight`](https://www.npmjs.com/package/@sig-net/midnight): the client-agnostic protocol library.
|
|
40
|
+
|
|
41
|
+
Developed in [sig-net/midnight-integration](https://github.com/sig-net/midnight-integration); example applications live in [sig-net/midnight-examples](https://github.com/sig-net/midnight-examples).
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,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,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
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,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,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,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { CompiledContract, Contract } from "@midnight-ntwrk/compact-js/effect";
|
|
|
2
2
|
import type { FacadeState } from "@midnightntwrk/wallet-sdk-facade";
|
|
3
3
|
import { type Types } from "effect";
|
|
4
4
|
import { type MidnightNodeConfig } from "./midnight-node-config.ts";
|
|
5
|
-
import type
|
|
5
|
+
import { type NetworkId } from "./network-id.ts";
|
|
6
6
|
/** Everything needed to perform a contract deploy: which stack to target, and which wallet pays for it. */
|
|
7
7
|
export interface DeployConfig {
|
|
8
8
|
/** The stack (node/indexer/proof-server endpoints + network id) to deploy to. */
|
|
@@ -10,13 +10,17 @@ export interface DeployConfig {
|
|
|
10
10
|
/** Seed (hex or mnemonic) of the wallet that funds & signs the deploy. */
|
|
11
11
|
readonly deployerSeed: string;
|
|
12
12
|
}
|
|
13
|
+
export declare const GENESIS_MINT_WALLET_SEED = "0000000000000000000000000000000000000000000000000000000000000001";
|
|
13
14
|
/**
|
|
14
|
-
* Read a {@link DeployConfig} from the environment.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Read a {@link DeployConfig} from the environment. Node config comes from
|
|
16
|
+
* {@link getMidnightNodeConfig}; the deployer seed from {@link resolveDeployerSeed}
|
|
17
|
+
* (genesis mint wallet on the local chain, a required funded `DEPLOYER_SEED`
|
|
18
|
+
* on every deployed network).
|
|
17
19
|
*
|
|
18
20
|
* @param env - The environment to read from; defaults to `process.env`.
|
|
19
21
|
* @returns The resolved deploy configuration.
|
|
22
|
+
* @throws If a deployed network lacks a valid funded `DEPLOYER_SEED` (see
|
|
23
|
+
* {@link resolveDeployerSeed}).
|
|
20
24
|
*/
|
|
21
25
|
export declare function getDeployConfig(env?: Record<string, string | undefined>): DeployConfig;
|
|
22
26
|
/** An unproven contract-deploy transaction, ready to balance/sign/prove/submit via a wallet. */
|
|
@@ -54,6 +58,19 @@ export declare function makeCompiledContract<C extends Contract.Contract<PS>, PS
|
|
|
54
58
|
* @returns The fully-bound {@link CompiledContract.CompiledContract}, ready for {@link buildDeployTransaction}.
|
|
55
59
|
*/
|
|
56
60
|
export declare function makeVacantCompiledContract<C extends Contract.Contract<PS>, PS>(tag: string, ctor: Types.Ctor<C>, managedDirPath: string): CompiledContract.CompiledContract<C, PS>;
|
|
61
|
+
/**
|
|
62
|
+
* Convert a contract address (hex, optional `0x`) into the reference shape a
|
|
63
|
+
* Compact contract-typed constructor arg expects: `{ bytes: Uint8Array(32) }`.
|
|
64
|
+
* Deploy scripts use this to seal a cross-contract reference (e.g. the
|
|
65
|
+
* central signet contract) read from the environment.
|
|
66
|
+
*
|
|
67
|
+
* @param contractAddress - The 32-byte contract address in hex.
|
|
68
|
+
* @returns The `{ bytes }` reference.
|
|
69
|
+
* @throws If the address is not 32 bytes of hex.
|
|
70
|
+
*/
|
|
71
|
+
export declare function contractAddressToReference(contractAddress: string): {
|
|
72
|
+
bytes: Uint8Array;
|
|
73
|
+
};
|
|
57
74
|
/**
|
|
58
75
|
* Build an UNPROVEN contract-deploy transaction: run the Compact constructor
|
|
59
76
|
* with `constructorArgs`, attach the verifier keys from the compiled assets,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/plumbing/deploy.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAsB,M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EACnB,SAAS,EAAE,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EACzC,cAAc,EAAE,MAAM,GACrB,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,CAI1C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,EAC5E,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EACnB,cAAc,EAAE,MAAM,GACrB,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,CAI1C;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,UAAU,CAAA;CAAE,CAUzF;AAKD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,SAAS,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,EAC9E,gBAAgB,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,EAC1D,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,MAAM,EACxB,mBAAmB,EAAE,EAAE,EACvB,GAAG,eAAe,EAAE,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,CAAC,GAC5D,OAAO,CAAC,iBAAiB,CAAC,CAiC5B;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAQ7D"}
|
package/dist/plumbing/deploy.js
CHANGED
|
@@ -11,22 +11,62 @@ import * as ledger from "@midnightntwrk/ledger-v9";
|
|
|
11
11
|
import * as Configuration from "@midnight-ntwrk/platform-js/effect/Configuration";
|
|
12
12
|
import * as CoinPublicKey from "@midnight-ntwrk/platform-js/effect/CoinPublicKey";
|
|
13
13
|
import { Effect, Layer, Option } from "effect";
|
|
14
|
-
import { getMidnightNodeConfig } from "./midnight-node-config.js";
|
|
14
|
+
import { getFaucetUrl, getMidnightNodeConfig } from "./midnight-node-config.js";
|
|
15
|
+
import { isLocalStandaloneNetwork } from "./network-id.js";
|
|
15
16
|
// Pre-funded genesis wallet of the local standalone stack — the default
|
|
16
|
-
// deployer for development.
|
|
17
|
-
const GENESIS_MINT_WALLET_SEED = "0000000000000000000000000000000000000000000000000000000000000001";
|
|
17
|
+
// deployer for development, and the ONLY network where it holds funds.
|
|
18
|
+
export const GENESIS_MINT_WALLET_SEED = "0000000000000000000000000000000000000000000000000000000000000001";
|
|
19
|
+
// True when `seed` is the genesis mint seed in hex form (0x-optional,
|
|
20
|
+
// case-insensitive). A mnemonic never matches. Used to reject the genesis
|
|
21
|
+
// seed on a deployed network, where it is unfunded.
|
|
22
|
+
function isGenesisSeed(seed) {
|
|
23
|
+
return seed.trim().replace(/^0x/i, "").toLowerCase() === GENESIS_MINT_WALLET_SEED;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the deployer seed for `networkId`. On the local standalone chain
|
|
27
|
+
* the genesis mint wallet is the default; on every deployed network the
|
|
28
|
+
* genesis wallet is unfunded, so a `DEPLOYER_SEED` funded via that network's
|
|
29
|
+
* faucet is required. The single consumer is {@link getDeployConfig}.
|
|
30
|
+
*
|
|
31
|
+
* @param env - The environment to read `DEPLOYER_SEED` from.
|
|
32
|
+
* @param networkId - The network the deploy targets.
|
|
33
|
+
* @returns The seed (hex or mnemonic) that funds & signs deploys.
|
|
34
|
+
* @throws If a deployed network has no `DEPLOYER_SEED`, or it is set to the
|
|
35
|
+
* (unfunded-here) genesis mint seed.
|
|
36
|
+
*/
|
|
37
|
+
function resolveDeployerSeed(env, networkId) {
|
|
38
|
+
const provided = env.DEPLOYER_SEED?.trim();
|
|
39
|
+
if (isLocalStandaloneNetwork(networkId)) {
|
|
40
|
+
return provided || GENESIS_MINT_WALLET_SEED;
|
|
41
|
+
}
|
|
42
|
+
const faucet = getFaucetUrl(env, networkId);
|
|
43
|
+
const fundHint = faucet ? `fund a wallet via ${faucet}` : "fund a wallet via the network's faucet";
|
|
44
|
+
if (!provided) {
|
|
45
|
+
throw new Error(`DEPLOYER_SEED is required on "${networkId}": the genesis mint seed only holds funds on the local ` +
|
|
46
|
+
`standalone chain. Set DEPLOYER_SEED (hex or mnemonic) to a funded wallet: ${fundHint}.`);
|
|
47
|
+
}
|
|
48
|
+
if (isGenesisSeed(provided)) {
|
|
49
|
+
throw new Error(`DEPLOYER_SEED is the local genesis mint seed, which holds no funds on "${networkId}". ` +
|
|
50
|
+
`${fundHint} and set DEPLOYER_SEED to it.`);
|
|
51
|
+
}
|
|
52
|
+
return provided;
|
|
53
|
+
}
|
|
18
54
|
/**
|
|
19
|
-
* Read a {@link DeployConfig} from the environment.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
55
|
+
* Read a {@link DeployConfig} from the environment. Node config comes from
|
|
56
|
+
* {@link getMidnightNodeConfig}; the deployer seed from {@link resolveDeployerSeed}
|
|
57
|
+
* (genesis mint wallet on the local chain, a required funded `DEPLOYER_SEED`
|
|
58
|
+
* on every deployed network).
|
|
22
59
|
*
|
|
23
60
|
* @param env - The environment to read from; defaults to `process.env`.
|
|
24
61
|
* @returns The resolved deploy configuration.
|
|
62
|
+
* @throws If a deployed network lacks a valid funded `DEPLOYER_SEED` (see
|
|
63
|
+
* {@link resolveDeployerSeed}).
|
|
25
64
|
*/
|
|
26
65
|
export function getDeployConfig(env = process.env) {
|
|
66
|
+
const midnightNodeConfig = getMidnightNodeConfig(env);
|
|
27
67
|
return {
|
|
28
|
-
midnightNodeConfig
|
|
29
|
-
deployerSeed: env.
|
|
68
|
+
midnightNodeConfig,
|
|
69
|
+
deployerSeed: resolveDeployerSeed(env, midnightNodeConfig.networkId),
|
|
30
70
|
};
|
|
31
71
|
}
|
|
32
72
|
/**
|
|
@@ -65,6 +105,27 @@ export function makeVacantCompiledContract(tag, ctor, managedDirPath) {
|
|
|
65
105
|
const vacant = CompiledContract.withVacantWitnesses(base);
|
|
66
106
|
return CompiledContract.withCompiledFileAssets(vacant, managedDirPath);
|
|
67
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Convert a contract address (hex, optional `0x`) into the reference shape a
|
|
110
|
+
* Compact contract-typed constructor arg expects: `{ bytes: Uint8Array(32) }`.
|
|
111
|
+
* Deploy scripts use this to seal a cross-contract reference (e.g. the
|
|
112
|
+
* central signet contract) read from the environment.
|
|
113
|
+
*
|
|
114
|
+
* @param contractAddress - The 32-byte contract address in hex.
|
|
115
|
+
* @returns The `{ bytes }` reference.
|
|
116
|
+
* @throws If the address is not 32 bytes of hex.
|
|
117
|
+
*/
|
|
118
|
+
export function contractAddressToReference(contractAddress) {
|
|
119
|
+
const hex = contractAddress.startsWith("0x") ? contractAddress.slice(2) : contractAddress;
|
|
120
|
+
if (!/^[0-9a-fA-F]{64}$/.test(hex)) {
|
|
121
|
+
throw new Error(`not a 32-byte contract address in hex: "${contractAddress}"`);
|
|
122
|
+
}
|
|
123
|
+
const bytes = new Uint8Array(32);
|
|
124
|
+
for (let i = 0; i < 32; i++) {
|
|
125
|
+
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
126
|
+
}
|
|
127
|
+
return { bytes };
|
|
128
|
+
}
|
|
68
129
|
// How long the deploy intent stays valid before it must be re-built.
|
|
69
130
|
const DEPLOY_TTL_MS = 30 * 60 * 1000;
|
|
70
131
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/plumbing/deploy.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yEAAyE;AACzE,0EAA0E;AAC1E,+EAA+E;AAC/E,+EAA+E;AAC/E,0DAA0D;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,QAAQ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,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACzF,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAEpG,OAAO;QACL,eAAe,EAAE,MAAM,CAAC,OAAO;QAC/B,qBAAqB,EAAE,WAAW,CAAC,SAAS,EAAE;KAC/C,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAkB;IACrD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IAC5C,IAAI,IAAI,GAAG,EAAE;QAAE,OAAO;IACtB,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,EAAE,EAAE,CAAC,CAAC;IAC/F,MAAM,IAAI,KAAK,CACb,2DAA2D,KAAK,KAAK;QACnE,6EAA6E,CAChF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { MidnightNodeConfig } from "./midnight-node-config.ts";
|
|
2
|
+
import { type WalletAddresses } from "./wallet.ts";
|
|
3
|
+
/** A wallet's synced funding snapshot: its addresses and NIGHT/DUST balances (base units). */
|
|
4
|
+
export interface AccountFunding {
|
|
5
|
+
/** The wallet's three bech32m addresses (network-prefixed). */
|
|
6
|
+
readonly addresses: WalletAddresses;
|
|
7
|
+
/** Total unshielded NIGHT held, in base units. */
|
|
8
|
+
readonly night: bigint;
|
|
9
|
+
/** Spendable DUST (fee) balance right now, in base units. */
|
|
10
|
+
readonly dust: bigint;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Derive a seed's three addresses without any network I/O. Convenience for
|
|
14
|
+
* printing a wallet's addresses before (or without) syncing it.
|
|
15
|
+
*
|
|
16
|
+
* @param seed - The wallet seed (hex or mnemonic).
|
|
17
|
+
* @param config - The stack whose network id prefixes the addresses.
|
|
18
|
+
* @returns The wallet's unshielded / shielded / dust addresses.
|
|
19
|
+
*/
|
|
20
|
+
export declare function deriveWalletAddresses(seed: string, config: MidnightNodeConfig): WalletAddresses;
|
|
21
|
+
/**
|
|
22
|
+
* Sync a wallet and read its funding snapshot (addresses + NIGHT + DUST).
|
|
23
|
+
*
|
|
24
|
+
* @param config - The stack the wallet connects to.
|
|
25
|
+
* @param seed - The wallet seed (hex or mnemonic).
|
|
26
|
+
* @returns The synced {@link AccountFunding}.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readAccountFunding(config: MidnightNodeConfig, seed: string): Promise<AccountFunding>;
|
|
29
|
+
/** A wallet is fee-ready when it holds NIGHT and that NIGHT has generated spendable dust. */
|
|
30
|
+
export declare function isFeeReady(funding: AccountFunding): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The root wallet holds no funds on a deployed network until its NIGHT
|
|
33
|
+
* receive address is faucet-funded. Thrown by {@link assertRootFunded} so the
|
|
34
|
+
* setup pipeline can STOP with the exact address and faucet URL to act on.
|
|
35
|
+
*/
|
|
36
|
+
export declare class RootUnfundedError extends Error {
|
|
37
|
+
readonly nightAddress: string;
|
|
38
|
+
readonly faucetUrl: string | undefined;
|
|
39
|
+
constructor(nightAddress: string, faucetUrl: string | undefined);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Ensure the root wallet is fee-ready, returning its snapshot. Root holds no
|
|
43
|
+
* NIGHT on a deployed network before faucet funding, so this throws
|
|
44
|
+
* {@link RootUnfundedError} (NIGHT address + faucet URL) when NIGHT is zero.
|
|
45
|
+
* On the local standalone chain, where genesis funds root by construction, a
|
|
46
|
+
* zero balance is instead retried until the indexer catches up (see
|
|
47
|
+
* {@link GENESIS_INDEX_TIMEOUT_MS}). Otherwise it registers root's NIGHT for
|
|
48
|
+
* dust generation and waits for a spendable DUST balance, because root pays
|
|
49
|
+
* the children's funding transfers in DUST: the local genesis root is already
|
|
50
|
+
* registered (a no-op here), but a faucet-funded root is not, and would have
|
|
51
|
+
* no DUST to spend.
|
|
52
|
+
*
|
|
53
|
+
* @param config - The stack the root wallet connects to.
|
|
54
|
+
* @param rootSeed - The root wallet seed.
|
|
55
|
+
* @param faucetUrl - The network's faucet URL for the underfunded message.
|
|
56
|
+
* @returns The root's fee-ready funding snapshot.
|
|
57
|
+
* @throws {@link RootUnfundedError} if root holds no NIGHT; or if no dust
|
|
58
|
+
* appears in time after registration.
|
|
59
|
+
*/
|
|
60
|
+
export declare function assertRootFunded(config: MidnightNodeConfig, rootSeed: string, faucetUrl: string | undefined): Promise<AccountFunding>;
|
|
61
|
+
/**
|
|
62
|
+
* Bring one child wallet to fee-ready by topping it up from root: if it holds
|
|
63
|
+
* no NIGHT, transfer `amount` from root and wait for the child to see it; then
|
|
64
|
+
* register the child's NIGHT for dust generation and wait for spendable dust.
|
|
65
|
+
* A child that already holds NIGHT but no dust yet is only registered + waited
|
|
66
|
+
* (no transfer). Call only for a child that is not already fee-ready.
|
|
67
|
+
*
|
|
68
|
+
* @param config - The stack both wallets connect to.
|
|
69
|
+
* @param rootSeed - The funding wallet's seed.
|
|
70
|
+
* @param childSeed - The child wallet's seed.
|
|
71
|
+
* @param amount - NIGHT to transfer when the child holds none, in base units.
|
|
72
|
+
* @returns The child's post-funding snapshot.
|
|
73
|
+
* @throws If root cannot cover the transfer, or dust never appears in time.
|
|
74
|
+
*/
|
|
75
|
+
export declare function fundChildFromRoot(config: MidnightNodeConfig, rootSeed: string, childSeed: string, amount: bigint): Promise<AccountFunding>;
|
|
76
|
+
//# sourceMappingURL=funding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funding.d.ts","sourceRoot":"","sources":["../../src/plumbing/funding.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EA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
|
|
|
1
|
+
// Account funding primitives for the root-funds-children model. Fees are paid
|
|
2
|
+
// in DUST, which only generates on NIGHT registered for dust generation, so a
|
|
3
|
+
// wallet is fee-ready only once it holds NIGHT that is registered and has
|
|
4
|
+
// generated spendable dust. One ROOT wallet (the local genesis mint, or a
|
|
5
|
+
// faucet-funded seed on a deployed network) holds the funds and pays out to
|
|
6
|
+
// the role wallets (deployer, invoker, mpc responder); the roles themselves
|
|
7
|
+
// are generated per environment and topped up from root.
|
|
8
|
+
//
|
|
9
|
+
// These are mechanical primitives (read a balance, assert root is funded,
|
|
10
|
+
// fund one child). The pipeline that resolves/persists seeds, decides the
|
|
11
|
+
// per-child amount, and prints addresses lives in the integration-tests setup.
|
|
12
|
+
import { isLocalStandaloneNetwork } from "./network-id.js";
|
|
13
|
+
import { deriveAccountKeys, deriveAddresses, registerNightForDustGeneration, transferNight, waitForSpendableDust, withSyncedWalletFacade, } from "./wallet.js";
|
|
14
|
+
/** Sum a wallet's unshielded NIGHT across its UTXOs, in base units. */
|
|
15
|
+
function totalNight(state) {
|
|
16
|
+
return Object.values(state.unshielded.balances).reduce((sum, value) => sum + value, 0n);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Derive a seed's three addresses without any network I/O. Convenience for
|
|
20
|
+
* printing a wallet's addresses before (or without) syncing it.
|
|
21
|
+
*
|
|
22
|
+
* @param seed - The wallet seed (hex or mnemonic).
|
|
23
|
+
* @param config - The stack whose network id prefixes the addresses.
|
|
24
|
+
* @returns The wallet's unshielded / shielded / dust addresses.
|
|
25
|
+
*/
|
|
26
|
+
export function deriveWalletAddresses(seed, config) {
|
|
27
|
+
return deriveAddresses(deriveAccountKeys(seed, config.networkId), config.networkId);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sync a wallet and read its funding snapshot (addresses + NIGHT + DUST).
|
|
31
|
+
*
|
|
32
|
+
* @param config - The stack the wallet connects to.
|
|
33
|
+
* @param seed - The wallet seed (hex or mnemonic).
|
|
34
|
+
* @returns The synced {@link AccountFunding}.
|
|
35
|
+
*/
|
|
36
|
+
export async function readAccountFunding(config, seed) {
|
|
37
|
+
const keys = deriveAccountKeys(seed, config.networkId);
|
|
38
|
+
const addresses = deriveAddresses(keys, config.networkId);
|
|
39
|
+
return withSyncedWalletFacade(keys, config, async (_facade, state) => ({
|
|
40
|
+
addresses,
|
|
41
|
+
night: totalNight(state),
|
|
42
|
+
dust: state.dust.balance(new Date()),
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
/** A wallet is fee-ready when it holds NIGHT and that NIGHT has generated spendable dust. */
|
|
46
|
+
export function isFeeReady(funding) {
|
|
47
|
+
return funding.night > 0n && funding.dust > 0n;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The root wallet holds no funds on a deployed network until its NIGHT
|
|
51
|
+
* receive address is faucet-funded. Thrown by {@link assertRootFunded} so the
|
|
52
|
+
* setup pipeline can STOP with the exact address and faucet URL to act on.
|
|
53
|
+
*/
|
|
54
|
+
export class RootUnfundedError extends Error {
|
|
55
|
+
nightAddress;
|
|
56
|
+
faucetUrl;
|
|
57
|
+
constructor(nightAddress, faucetUrl) {
|
|
58
|
+
const where = faucetUrl ? `at ${faucetUrl}` : "via the network's faucet";
|
|
59
|
+
super(`root wallet holds no NIGHT. Fund it ${where}, then rerun.\n` +
|
|
60
|
+
` NIGHT address: ${nightAddress}` +
|
|
61
|
+
(faucetUrl ? `\n faucet: ${faucetUrl}` : ""));
|
|
62
|
+
this.nightAddress = nightAddress;
|
|
63
|
+
this.faucetUrl = faucetUrl;
|
|
64
|
+
this.name = "RootUnfundedError";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// A freshly composed local stack has a window where the indexer reports a
|
|
68
|
+
// synced (empty) state before it has indexed the genesis block that funds the
|
|
69
|
+
// genesis mint wallet — so a zero root balance there means "not indexed yet",
|
|
70
|
+
// not "unfunded". Poll until the genesis funds appear.
|
|
71
|
+
const GENESIS_INDEX_POLL_INTERVAL_MS = 3_000;
|
|
72
|
+
const GENESIS_INDEX_TIMEOUT_MS = 120_000;
|
|
73
|
+
/**
|
|
74
|
+
* Ensure the root wallet is fee-ready, returning its snapshot. Root holds no
|
|
75
|
+
* NIGHT on a deployed network before faucet funding, so this throws
|
|
76
|
+
* {@link RootUnfundedError} (NIGHT address + faucet URL) when NIGHT is zero.
|
|
77
|
+
* On the local standalone chain, where genesis funds root by construction, a
|
|
78
|
+
* zero balance is instead retried until the indexer catches up (see
|
|
79
|
+
* {@link GENESIS_INDEX_TIMEOUT_MS}). Otherwise it registers root's NIGHT for
|
|
80
|
+
* dust generation and waits for a spendable DUST balance, because root pays
|
|
81
|
+
* the children's funding transfers in DUST: the local genesis root is already
|
|
82
|
+
* registered (a no-op here), but a faucet-funded root is not, and would have
|
|
83
|
+
* no DUST to spend.
|
|
84
|
+
*
|
|
85
|
+
* @param config - The stack the root wallet connects to.
|
|
86
|
+
* @param rootSeed - The root wallet seed.
|
|
87
|
+
* @param faucetUrl - The network's faucet URL for the underfunded message.
|
|
88
|
+
* @returns The root's fee-ready funding snapshot.
|
|
89
|
+
* @throws {@link RootUnfundedError} if root holds no NIGHT; or if no dust
|
|
90
|
+
* appears in time after registration.
|
|
91
|
+
*/
|
|
92
|
+
export async function assertRootFunded(config, rootSeed, faucetUrl) {
|
|
93
|
+
const keys = deriveAccountKeys(rootSeed, config.networkId);
|
|
94
|
+
const addresses = deriveAddresses(keys, config.networkId);
|
|
95
|
+
return withSyncedWalletFacade(keys, config, async (facade, state) => {
|
|
96
|
+
let night = totalNight(state);
|
|
97
|
+
if (night === 0n && isLocalStandaloneNetwork(config.networkId)) {
|
|
98
|
+
const deadline = Date.now() + GENESIS_INDEX_TIMEOUT_MS;
|
|
99
|
+
while (night === 0n && Date.now() < deadline) {
|
|
100
|
+
await new Promise((resolve) => setTimeout(resolve, GENESIS_INDEX_POLL_INTERVAL_MS));
|
|
101
|
+
state = await facade.waitForSyncedState();
|
|
102
|
+
night = totalNight(state);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (night === 0n) {
|
|
106
|
+
throw new RootUnfundedError(addresses.unshielded, faucetUrl);
|
|
107
|
+
}
|
|
108
|
+
await registerNightForDustGeneration(facade, keys, state);
|
|
109
|
+
const dustNow = state.dust.balance(new Date());
|
|
110
|
+
const dust = dustNow > 0n ? dustNow : await waitForSpendableDust(facade);
|
|
111
|
+
return { addresses, night, dust };
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Bring one child wallet to fee-ready by topping it up from root: if it holds
|
|
116
|
+
* no NIGHT, transfer `amount` from root and wait for the child to see it; then
|
|
117
|
+
* register the child's NIGHT for dust generation and wait for spendable dust.
|
|
118
|
+
* A child that already holds NIGHT but no dust yet is only registered + waited
|
|
119
|
+
* (no transfer). Call only for a child that is not already fee-ready.
|
|
120
|
+
*
|
|
121
|
+
* @param config - The stack both wallets connect to.
|
|
122
|
+
* @param rootSeed - The funding wallet's seed.
|
|
123
|
+
* @param childSeed - The child wallet's seed.
|
|
124
|
+
* @param amount - NIGHT to transfer when the child holds none, in base units.
|
|
125
|
+
* @returns The child's post-funding snapshot.
|
|
126
|
+
* @throws If root cannot cover the transfer, or dust never appears in time.
|
|
127
|
+
*/
|
|
128
|
+
export async function fundChildFromRoot(config, rootSeed, childSeed, amount) {
|
|
129
|
+
const rootKeys = deriveAccountKeys(rootSeed, config.networkId);
|
|
130
|
+
const childKeys = deriveAccountKeys(childSeed, config.networkId);
|
|
131
|
+
const childAddresses = deriveAddresses(childKeys, config.networkId);
|
|
132
|
+
const before = await withSyncedWalletFacade(childKeys, config, async (_f, s) => totalNight(s));
|
|
133
|
+
if (before === 0n) {
|
|
134
|
+
await withSyncedWalletFacade(rootKeys, config, async (rootFacade, rootState) => {
|
|
135
|
+
await transferNight(rootFacade, rootKeys, rootState, childAddresses.unshielded, config.networkId, amount);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return withSyncedWalletFacade(childKeys, config, async (childFacade, childState) => {
|
|
139
|
+
// Wait for the transferred NIGHT UTXO to land in the child's synced view.
|
|
140
|
+
let state = childState;
|
|
141
|
+
for (let i = 0; i < 40 && totalNight(state) === 0n; i++) {
|
|
142
|
+
await new Promise((resolve) => setTimeout(resolve, 3_000));
|
|
143
|
+
state = await childFacade.waitForSyncedState();
|
|
144
|
+
}
|
|
145
|
+
if (totalNight(state) === 0n) {
|
|
146
|
+
throw new Error(`child wallet ${childAddresses.unshielded} shows no NIGHT after funding from root`);
|
|
147
|
+
}
|
|
148
|
+
await registerNightForDustGeneration(childFacade, childKeys, state);
|
|
149
|
+
const dust = await waitForSpendableDust(childFacade);
|
|
150
|
+
return { addresses: childAddresses, night: totalNight(state), dust };
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=funding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funding.js","sourceRoot":"","sources":["../../src/plumbing/funding.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,8EAA8E;AAC9E,0EAA0E;AAC1E,0EAA0E;AAC1E,4EAA4E;AAC5E,4EAA4E;AAC5E,yDAAyD;AACzD,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,+EAA+E;AAG/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,8BAA8B,EAC9B,aAAa,EACb,oBAAoB,EACpB,sBAAsB,GAGvB,MAAM,aAAa,CAAC;AAYrB,uEAAuE;AACvE,SAAS,UAAU,CAAC,KAAkB;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,EAAE,EAAE,CAAC,CAAC;AAC1F,CAAC;AAED;;;;;;;GAOG;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AED,OAAO,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE;QACjF,0EAA0E;QAC1E,IAAI,KAAK,GAAG,UAAU,CAAC;QACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;YACxD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;YAC3D,KAAK,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,CAAC;QACjD,CAAC;QACD,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,gBAAgB,cAAc,CAAC,UAAU,yCAAyC,CAAC,CAAC;QACtG,CAAC;QACD,MAAM,8BAA8B,CAAC,WAAW,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QACpE,MAAM,IAAI,GAAG,MAAM,oBAAoB,CAAC,WAAW,CAAC,CAAC;QACrD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -15,10 +15,23 @@ export interface MidnightNodeConfig {
|
|
|
15
15
|
export type Endpoints = Omit<MidnightNodeConfig, "networkId">;
|
|
16
16
|
export declare const LOCAL_PROOF_SERVER = "http://127.0.0.1:6300";
|
|
17
17
|
export declare const DEFAULT_ENDPOINTS: Record<NetworkId, Endpoints>;
|
|
18
|
+
export declare const FAUCET_URLS: Partial<Record<NetworkId, string>>;
|
|
19
|
+
/**
|
|
20
|
+
* The faucet URL to show in underfunded-wallet hints: `MIDNIGHT_FAUCET_URL`
|
|
21
|
+
* from the environment when set, else the network's {@link FAUCET_URLS}
|
|
22
|
+
* entry. Purely informational — a missing URL only makes the hint generic.
|
|
23
|
+
*
|
|
24
|
+
* @param env - The environment to read `MIDNIGHT_FAUCET_URL` from.
|
|
25
|
+
* @param networkId - The network whose faucet the hint points at.
|
|
26
|
+
* @returns The faucet URL, or undefined when none is known.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getFaucetUrl(env: Record<string, string | undefined>, networkId: NetworkId): string | undefined;
|
|
18
29
|
export declare function indexerWsUrlFromIndexerUrl(indexerUrl: string): string;
|
|
19
30
|
/**
|
|
20
|
-
* Read a {@link MidnightNodeConfig} from the environment.
|
|
21
|
-
*
|
|
31
|
+
* Read a {@link MidnightNodeConfig} from the environment. With nothing set
|
|
32
|
+
* this yields the local "undeployed" stack; a network with blank defaults
|
|
33
|
+
* (stagenet — its endpoints are not published in this repo) REQUIRES the
|
|
34
|
+
* endpoint variables and fails naming the missing ones.
|
|
22
35
|
*
|
|
23
36
|
* Parse flow:
|
|
24
37
|
* 1. `NETWORK_ID` (default "undeployed", validated against {@link NETWORK_IDS})
|
|
@@ -28,6 +41,10 @@ export declare function indexerWsUrlFromIndexerUrl(indexerUrl: string): string;
|
|
|
28
41
|
* `MIDNIGHT_NODE_INDEXER_WS_URL`, `MIDNIGHT_NODE_PROOF_SERVER_URL`.
|
|
29
42
|
* When the indexer URL is overridden without a WS override, the WS URL is
|
|
30
43
|
* derived from it instead of keeping the baseline host.
|
|
44
|
+
* 3. Every resolved endpoint must be non-empty.
|
|
45
|
+
*
|
|
46
|
+
* @throws If `NETWORK_ID` is unknown, or an endpoint resolves empty (blank
|
|
47
|
+
* default and no environment override).
|
|
31
48
|
*/
|
|
32
49
|
export declare function getMidnightNodeConfig(env?: Record<string, string | undefined>): MidnightNodeConfig;
|
|
33
50
|
//# sourceMappingURL=midnight-node-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"midnight-node-config.d.ts","sourceRoot":"","sources":["../../src/plumbing/midnight-node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AElE;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EACvC,SAAS,EAAE,SAAS,GACnB,MAAM,GAAG,SAAS,CAEpB;AAID,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,kBAAkB,CAoCpB"}
|
|
@@ -12,6 +12,20 @@ export const DEFAULT_ENDPOINTS = {
|
|
|
12
12
|
nodeUrl: "http://127.0.0.1:9944",
|
|
13
13
|
proofServerUrl: LOCAL_PROOF_SERVER,
|
|
14
14
|
},
|
|
15
|
+
// Stagenet's endpoints are deliberately NOT published in this repo.
|
|
16
|
+
// Provide them via the environment (repo-root .env), which
|
|
17
|
+
// getMidnightNodeConfig REQUIRES for this network:
|
|
18
|
+
// MIDNIGHT_NODE_URL — node RPC
|
|
19
|
+
// MIDNIGHT_NODE_INDEXER_URL — indexer GraphQL over HTTP (the WS
|
|
20
|
+
// twin derives from it when unset)
|
|
21
|
+
// MIDNIGHT_NODE_INDEXER_WS_URL — indexer GraphQL over WebSocket
|
|
22
|
+
// The proof server stays local (it sees private witness data).
|
|
23
|
+
["stagenet"]: {
|
|
24
|
+
indexerUrl: "",
|
|
25
|
+
indexerWsUrl: "",
|
|
26
|
+
nodeUrl: "",
|
|
27
|
+
proofServerUrl: LOCAL_PROOF_SERVER,
|
|
28
|
+
},
|
|
15
29
|
["preview"]: {
|
|
16
30
|
indexerUrl: "https://indexer.preview.midnight.network/api/v3/graphql",
|
|
17
31
|
indexerWsUrl: "wss://indexer.preview.midnight.network/api/v3/graphql/ws",
|
|
@@ -31,6 +45,26 @@ export const DEFAULT_ENDPOINTS = {
|
|
|
31
45
|
proofServerUrl: LOCAL_PROOF_SERVER,
|
|
32
46
|
},
|
|
33
47
|
};
|
|
48
|
+
// Faucet URLs for the networks that publish one, for underfunded-wallet
|
|
49
|
+
// hints. The local standalone chain funds via genesis, not a faucet, so it
|
|
50
|
+
// has no entry. Stagenet's faucet URL is deliberately NOT published in this
|
|
51
|
+
// repo — provide it via the MIDNIGHT_FAUCET_URL environment variable (see
|
|
52
|
+
// {@link getFaucetUrl}); without it the hint degrades to a generic "fund via
|
|
53
|
+
// the network's faucet". The public *.midnight.network faucet URLs are
|
|
54
|
+
// omitted until confirmed.
|
|
55
|
+
export const FAUCET_URLS = {};
|
|
56
|
+
/**
|
|
57
|
+
* The faucet URL to show in underfunded-wallet hints: `MIDNIGHT_FAUCET_URL`
|
|
58
|
+
* from the environment when set, else the network's {@link FAUCET_URLS}
|
|
59
|
+
* entry. Purely informational — a missing URL only makes the hint generic.
|
|
60
|
+
*
|
|
61
|
+
* @param env - The environment to read `MIDNIGHT_FAUCET_URL` from.
|
|
62
|
+
* @param networkId - The network whose faucet the hint points at.
|
|
63
|
+
* @returns The faucet URL, or undefined when none is known.
|
|
64
|
+
*/
|
|
65
|
+
export function getFaucetUrl(env, networkId) {
|
|
66
|
+
return env.MIDNIGHT_FAUCET_URL?.trim() || FAUCET_URLS[networkId];
|
|
67
|
+
}
|
|
34
68
|
// Derive the indexer WebSocket URL from the indexer HTTP URL: swap the scheme
|
|
35
69
|
// to ws(s) and append the "/ws" path segment the indexer expects.
|
|
36
70
|
export function indexerWsUrlFromIndexerUrl(indexerUrl) {
|
|
@@ -40,8 +74,10 @@ export function indexerWsUrlFromIndexerUrl(indexerUrl) {
|
|
|
40
74
|
return url.toString();
|
|
41
75
|
}
|
|
42
76
|
/**
|
|
43
|
-
* Read a {@link MidnightNodeConfig} from the environment.
|
|
44
|
-
*
|
|
77
|
+
* Read a {@link MidnightNodeConfig} from the environment. With nothing set
|
|
78
|
+
* this yields the local "undeployed" stack; a network with blank defaults
|
|
79
|
+
* (stagenet — its endpoints are not published in this repo) REQUIRES the
|
|
80
|
+
* endpoint variables and fails naming the missing ones.
|
|
45
81
|
*
|
|
46
82
|
* Parse flow:
|
|
47
83
|
* 1. `NETWORK_ID` (default "undeployed", validated against {@link NETWORK_IDS})
|
|
@@ -51,6 +87,10 @@ export function indexerWsUrlFromIndexerUrl(indexerUrl) {
|
|
|
51
87
|
* `MIDNIGHT_NODE_INDEXER_WS_URL`, `MIDNIGHT_NODE_PROOF_SERVER_URL`.
|
|
52
88
|
* When the indexer URL is overridden without a WS override, the WS URL is
|
|
53
89
|
* derived from it instead of keeping the baseline host.
|
|
90
|
+
* 3. Every resolved endpoint must be non-empty.
|
|
91
|
+
*
|
|
92
|
+
* @throws If `NETWORK_ID` is unknown, or an endpoint resolves empty (blank
|
|
93
|
+
* default and no environment override).
|
|
54
94
|
*/
|
|
55
95
|
export function getMidnightNodeConfig(env = process.env) {
|
|
56
96
|
const networkId = env.NETWORK_ID?.trim() || "undeployed";
|
|
@@ -61,12 +101,29 @@ export function getMidnightNodeConfig(env = process.env) {
|
|
|
61
101
|
const indexerUrl = env.MIDNIGHT_NODE_INDEXER_URL || defaults.indexerUrl;
|
|
62
102
|
const indexerWsUrl = env.MIDNIGHT_NODE_INDEXER_WS_URL ||
|
|
63
103
|
(env.MIDNIGHT_NODE_INDEXER_URL ? indexerWsUrlFromIndexerUrl(indexerUrl) : defaults.indexerWsUrl);
|
|
64
|
-
|
|
104
|
+
const config = {
|
|
65
105
|
networkId,
|
|
66
106
|
indexerUrl,
|
|
67
107
|
indexerWsUrl,
|
|
68
108
|
nodeUrl: env.MIDNIGHT_NODE_URL || defaults.nodeUrl,
|
|
69
109
|
proofServerUrl: env.MIDNIGHT_NODE_PROOF_SERVER_URL || defaults.proofServerUrl,
|
|
70
110
|
};
|
|
111
|
+
// A blank default means the network's endpoints are not published in this
|
|
112
|
+
// repo (stagenet) — the environment must supply them, so fail with the
|
|
113
|
+
// exact variables to set.
|
|
114
|
+
const missing = [];
|
|
115
|
+
if (!config.nodeUrl)
|
|
116
|
+
missing.push("MIDNIGHT_NODE_URL");
|
|
117
|
+
if (!config.indexerUrl)
|
|
118
|
+
missing.push("MIDNIGHT_NODE_INDEXER_URL");
|
|
119
|
+
if (!config.indexerWsUrl)
|
|
120
|
+
missing.push("MIDNIGHT_NODE_INDEXER_WS_URL");
|
|
121
|
+
if (!config.proofServerUrl)
|
|
122
|
+
missing.push("MIDNIGHT_NODE_PROOF_SERVER_URL");
|
|
123
|
+
if (missing.length > 0) {
|
|
124
|
+
throw new Error(`network "${networkId}" has no built-in endpoints in this repo — set ${missing.join(", ")} ` +
|
|
125
|
+
`in the environment (or the repo-root .env).`);
|
|
126
|
+
}
|
|
127
|
+
return config;
|
|
71
128
|
}
|
|
72
129
|
//# sourceMappingURL=midnight-node-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"midnight-node-config.js","sourceRoot":"","sources":["../../src/plumbing/midnight-node-config.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAE9E,OAAO,EAAE,WAAW,EAAkB,MAAM,iBAAiB,CAAC;AAkB9D,0EAA0E;AAC1E,qCAAqC;AACrC,MAAM,CAAC,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAE1D,0EAA0E;AAC1E,8CAA8C;AAC9C,MAAM,CAAC,MAAM,iBAAiB,GAAiC;IAC7D,CAAC,YAAY,CAAC,EAAE;QACd,UAAU,EAAE,sCAAsC;QAClD,YAAY,EAAE,uCAAuC;QACrD,OAAO,EAAE,uBAAuB;QAChC,cAAc,EAAE,kBAAkB;KACnC;IACD,CAAC,SAAS,CAAC,EAAE;QACX,UAAU,EAAE,yDAAyD;QACrE,YAAY,EAAE,0DAA0D;QACxE,OAAO,EAAE,sCAAsC;QAC/C,cAAc,EAAE,kBAAkB;KACnC;IACD,CAAC,SAAS,CAAC,EAAE;QACX,UAAU,EAAE,yDAAyD;QACrE,YAAY,EAAE,0DAA0D;QACxE,OAAO,EAAE,sCAAsC;QAC/C,cAAc,EAAE,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CAAC,cAAc;QAAE,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;IAC3E,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,YAAY,SAAS,kDAAkD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YAC1F,6CAA6C,CAChD,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { NetworkId as MidnightSDKNetworkId } from "@midnight-ntwrk/midnight-js/network-id";
|
|
2
2
|
/** A Midnight network id: the SDK's bare-string type plus our known named networks. */
|
|
3
|
-
export type NetworkId = MidnightSDKNetworkId | "undeployed" | "preview" | "preprod" | "mainnet";
|
|
3
|
+
export type NetworkId = MidnightSDKNetworkId | "undeployed" | "stagenet" | "preview" | "preprod" | "mainnet";
|
|
4
4
|
export declare const NETWORK_IDS: readonly NetworkId[];
|
|
5
|
+
/**
|
|
6
|
+
* Whether a network's genesis mint wallet is pre-funded. TRUE only for the
|
|
7
|
+
* local standalone chain (`undeployed`), whose genesis block mints to the
|
|
8
|
+
* well-known genesis seed. Every deployed network (preview / preprod /
|
|
9
|
+
* stagenet / mainnet) starts each wallet at zero, so a run against one needs
|
|
10
|
+
* a seed funded out of band (via that network's faucet).
|
|
11
|
+
*
|
|
12
|
+
* @param networkId - The network to classify.
|
|
13
|
+
* @returns Whether the genesis mint wallet holds spendable funds here.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isLocalStandaloneNetwork(networkId: NetworkId): boolean;
|
|
5
16
|
//# sourceMappingURL=network-id.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-id.d.ts","sourceRoot":"","sources":["../../src/plumbing/network-id.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,IAAI,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAEhG,uFAAuF;AACvF,MAAM,MAAM,SAAS,GAEjB,oBAAoB,GAEpB,YAAY,GAEZ,SAAS,GAET,SAAS,GAET,SAAS,CAAC;AAGd,eAAO,MAAM,WAAW,EAAE,SAAS,SAAS,
|
|
1
|
+
{"version":3,"file":"network-id.d.ts","sourceRoot":"","sources":["../../src/plumbing/network-id.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,IAAI,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAEhG,uFAAuF;AACvF,MAAM,MAAM,SAAS,GAEjB,oBAAoB,GAEpB,YAAY,GAEZ,UAAU,GAEV,SAAS,GAET,SAAS,GAET,SAAS,CAAC;AAGd,eAAO,MAAM,WAAW,EAAE,SAAS,SAAS,EAM3C,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAEtE"}
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
// All known network ids, for runtime validation and iteration.
|
|
2
2
|
export const NETWORK_IDS = [
|
|
3
3
|
"undeployed",
|
|
4
|
+
"stagenet",
|
|
4
5
|
"preview",
|
|
5
6
|
"preprod",
|
|
6
7
|
"mainnet",
|
|
7
8
|
];
|
|
9
|
+
/**
|
|
10
|
+
* Whether a network's genesis mint wallet is pre-funded. TRUE only for the
|
|
11
|
+
* local standalone chain (`undeployed`), whose genesis block mints to the
|
|
12
|
+
* well-known genesis seed. Every deployed network (preview / preprod /
|
|
13
|
+
* stagenet / mainnet) starts each wallet at zero, so a run against one needs
|
|
14
|
+
* a seed funded out of band (via that network's faucet).
|
|
15
|
+
*
|
|
16
|
+
* @param networkId - The network to classify.
|
|
17
|
+
* @returns Whether the genesis mint wallet holds spendable funds here.
|
|
18
|
+
*/
|
|
19
|
+
export function isLocalStandaloneNetwork(networkId) {
|
|
20
|
+
return networkId === "undeployed";
|
|
21
|
+
}
|
|
8
22
|
//# sourceMappingURL=network-id.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-id.js","sourceRoot":"","sources":["../../src/plumbing/network-id.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"network-id.js","sourceRoot":"","sources":["../../src/plumbing/network-id.ts"],"names":[],"mappings":"AAsBA,+DAA+D;AAC/D,MAAM,CAAC,MAAM,WAAW,GAAyB;IAC7C,YAAY;IACZ,UAAU;IACV,SAAS;IACT,SAAS;IACT,SAAS;CACZ,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAAoB;IACzD,OAAO,SAAS,KAAK,YAAY,CAAC;AACtC,CAAC"}
|
package/dist/plumbing/seed.d.ts
CHANGED
|
@@ -26,11 +26,20 @@ export declare function parseSeed(input: string): {
|
|
|
26
26
|
};
|
|
27
27
|
/** Generate a fresh random 24-word BIP-39 mnemonic (256 bits of entropy). */
|
|
28
28
|
export declare function generateMnemonic(): string;
|
|
29
|
+
/**
|
|
30
|
+
* Generate a fresh random 32-byte seed as lowercase hex (no `0x` prefix).
|
|
31
|
+
* Preferred over a mnemonic for generated role wallets: it parses through
|
|
32
|
+
* {@link parseSeed} AND is the shape non-JS consumers expect (e.g. the
|
|
33
|
+
* fakenet responder container reads its wallet seed as raw hex).
|
|
34
|
+
*
|
|
35
|
+
* @returns 64 hex chars (32 bytes) of cryptographically-random seed.
|
|
36
|
+
*/
|
|
37
|
+
export declare function generateHexSeed(): string;
|
|
29
38
|
/**
|
|
30
39
|
* Resolve a 32-byte identity secret key from the environment: `env[envVar]`
|
|
31
40
|
* (hex, optional 0x prefix) when set, else the bytes of `fallbackSeed` (the
|
|
32
41
|
* wallet seed doubling as the identity). Contract packages use this for the
|
|
33
|
-
* secret whose commitment gates a circuit (e.g.
|
|
42
|
+
* secret whose commitment gates a circuit (e.g. a deployer identity),
|
|
34
43
|
* and clients use it for the caller identity answering a secret-key witness.
|
|
35
44
|
*
|
|
36
45
|
* @param envVar - Name of the environment variable holding the hex secret.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../src/plumbing/seed.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../src/plumbing/seed.ts"],"names":[],"mappings":"AASA,gFAAgF;AAChF,eAAO,MAAM,UAAU;;;CAGb,CAAC;AACX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAEtE,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,UAAU,CAAC;IACnB,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,UAAW,SAAQ,KAAK;CAAG;AAExC;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAyBvF;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EACvC,YAAY,EAAE,MAAM,GACnB,UAAU,CAiBZ"}
|
package/dist/plumbing/seed.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Seed parsing — turns user input (a BIP-39 mnemonic or a raw hex seed) into
|
|
2
2
|
// the seed bytes the HD wallet derives from, plus a record of how it was
|
|
3
3
|
// supplied (so the normalised hex form can be used as a stable identifier).
|
|
4
|
+
import { randomBytes } from "node:crypto";
|
|
4
5
|
import * as bip39 from "@scure/bip39";
|
|
5
6
|
import { wordlist as english } from "@scure/bip39/wordlists/english.js";
|
|
6
7
|
const toHex = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
@@ -44,11 +45,22 @@ export function parseSeed(input) {
|
|
|
44
45
|
export function generateMnemonic() {
|
|
45
46
|
return bip39.generateMnemonic(english, 256);
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Generate a fresh random 32-byte seed as lowercase hex (no `0x` prefix).
|
|
50
|
+
* Preferred over a mnemonic for generated role wallets: it parses through
|
|
51
|
+
* {@link parseSeed} AND is the shape non-JS consumers expect (e.g. the
|
|
52
|
+
* fakenet responder container reads its wallet seed as raw hex).
|
|
53
|
+
*
|
|
54
|
+
* @returns 64 hex chars (32 bytes) of cryptographically-random seed.
|
|
55
|
+
*/
|
|
56
|
+
export function generateHexSeed() {
|
|
57
|
+
return toHex(randomBytes(32));
|
|
58
|
+
}
|
|
47
59
|
/**
|
|
48
60
|
* Resolve a 32-byte identity secret key from the environment: `env[envVar]`
|
|
49
61
|
* (hex, optional 0x prefix) when set, else the bytes of `fallbackSeed` (the
|
|
50
62
|
* wallet seed doubling as the identity). Contract packages use this for the
|
|
51
|
-
* secret whose commitment gates a circuit (e.g.
|
|
63
|
+
* secret whose commitment gates a circuit (e.g. a deployer identity),
|
|
52
64
|
* and clients use it for the caller identity answering a secret-key witness.
|
|
53
65
|
*
|
|
54
66
|
* @param envVar - Name of the environment variable holding the hex secret.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.js","sourceRoot":"","sources":["../../src/plumbing/seed.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,yEAAyE;AACzE,4EAA4E;AAC5E,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAExE,MAAM,KAAK,GAAG,CAAC,KAAiB,EAAE,EAAE,CAAC,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IAAI,CAAC;AACd,CAAC"}
|
|
@@ -50,6 +50,24 @@ export declare function initialiseWalletFacade(keys: AccountKeys, config: Midnig
|
|
|
50
50
|
* @throws If the wallet cannot cover fees, proving fails, or the node rejects the transaction.
|
|
51
51
|
*/
|
|
52
52
|
export declare function submitUnprovenTransaction(facade: WalletFacade, keys: AccountKeys, serializedTransaction: Uint8Array): Promise<TransactionIdentifier>;
|
|
53
|
+
/**
|
|
54
|
+
* Transfer unshielded NIGHT from a started wallet to another wallet's
|
|
55
|
+
* unshielded (NIGHT receive) address: build the transfer recipe, sign its
|
|
56
|
+
* inputs, prove, and submit. Fees are paid in the sender's DUST (`payFees`),
|
|
57
|
+
* so the sender must already be dust-generating. The NIGHT token type is read
|
|
58
|
+
* from the sender's synced state (these chains carry a single unshielded
|
|
59
|
+
* token), so no token constant is hard-coded.
|
|
60
|
+
*
|
|
61
|
+
* @param facade - A started, synced, dust-generating wallet facade (the funder).
|
|
62
|
+
* @param keys - The funder's key material, for balancing and signing.
|
|
63
|
+
* @param state - The funder's synced state, read for its NIGHT token type.
|
|
64
|
+
* @param toUnshieldedAddress - The recipient's unshielded address (bech32m, network-prefixed).
|
|
65
|
+
* @param networkId - The network both wallets live on (decodes the address).
|
|
66
|
+
* @param amount - NIGHT to send, in base units.
|
|
67
|
+
* @returns The submitted transaction's identifier.
|
|
68
|
+
* @throws If the sender holds no unshielded NIGHT, or balancing/proving/submission fails.
|
|
69
|
+
*/
|
|
70
|
+
export declare function transferNight(facade: WalletFacade, keys: AccountKeys, state: FacadeState, toUnshieldedAddress: string, networkId: NetworkId, amount: bigint): Promise<TransactionIdentifier>;
|
|
53
71
|
/**
|
|
54
72
|
* Register every NIGHT UTXO not yet registered for dust generation, so the
|
|
55
73
|
* wallet can pay transaction fees (fees are paid in DUST, which only
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/plumbing/wallet.ts"],"names":[],"mappings":"AAIA,OAAO,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,7 @@ import { ShieldedWallet } from "@midnightntwrk/wallet-sdk-shielded";
|
|
|
9
9
|
import { DustWallet } from "@midnightntwrk/wallet-sdk-dust-wallet";
|
|
10
10
|
import { createKeystore, PublicKey as UnshieldedPublicKey, UnshieldedWallet, } from "@midnightntwrk/wallet-sdk-unshielded-wallet";
|
|
11
11
|
import { InMemoryTransactionHistoryStorage } from "@midnightntwrk/wallet-sdk-abstractions";
|
|
12
|
-
import { DustAddress, MidnightBech32m, ShieldedAddress, ShieldedCoinPublicKey, ShieldedEncryptionPublicKey, } from "@midnightntwrk/wallet-sdk-address-format";
|
|
12
|
+
import { DustAddress, MidnightBech32m, ShieldedAddress, ShieldedCoinPublicKey, ShieldedEncryptionPublicKey, UnshieldedAddress, } from "@midnightntwrk/wallet-sdk-address-format";
|
|
13
13
|
import { parseSeed } from "./seed.js";
|
|
14
14
|
/**
|
|
15
15
|
* The fee settings the facade balances transactions with: it burns
|
|
@@ -95,6 +95,34 @@ export async function submitUnprovenTransaction(facade, keys, serializedTransact
|
|
|
95
95
|
const finalized = await facade.finalizeRecipe(signed);
|
|
96
96
|
return facade.submitTransaction(finalized);
|
|
97
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Transfer unshielded NIGHT from a started wallet to another wallet's
|
|
100
|
+
* unshielded (NIGHT receive) address: build the transfer recipe, sign its
|
|
101
|
+
* inputs, prove, and submit. Fees are paid in the sender's DUST (`payFees`),
|
|
102
|
+
* so the sender must already be dust-generating. The NIGHT token type is read
|
|
103
|
+
* from the sender's synced state (these chains carry a single unshielded
|
|
104
|
+
* token), so no token constant is hard-coded.
|
|
105
|
+
*
|
|
106
|
+
* @param facade - A started, synced, dust-generating wallet facade (the funder).
|
|
107
|
+
* @param keys - The funder's key material, for balancing and signing.
|
|
108
|
+
* @param state - The funder's synced state, read for its NIGHT token type.
|
|
109
|
+
* @param toUnshieldedAddress - The recipient's unshielded address (bech32m, network-prefixed).
|
|
110
|
+
* @param networkId - The network both wallets live on (decodes the address).
|
|
111
|
+
* @param amount - NIGHT to send, in base units.
|
|
112
|
+
* @returns The submitted transaction's identifier.
|
|
113
|
+
* @throws If the sender holds no unshielded NIGHT, or balancing/proving/submission fails.
|
|
114
|
+
*/
|
|
115
|
+
export async function transferNight(facade, keys, state, toUnshieldedAddress, networkId, amount) {
|
|
116
|
+
const nightTokenType = Object.keys(state.unshielded.balances)[0];
|
|
117
|
+
if (!nightTokenType) {
|
|
118
|
+
throw new Error("funder wallet holds no unshielded NIGHT to transfer");
|
|
119
|
+
}
|
|
120
|
+
const receiverAddress = MidnightBech32m.parse(toUnshieldedAddress).decode(UnshieldedAddress, networkId);
|
|
121
|
+
const recipe = await facade.transferTransaction([{ type: "unshielded", outputs: [{ type: nightTokenType, receiverAddress, amount }] }], { shieldedSecretKeys: keys.shieldedSecretKeys, dustSecretKey: keys.dustSecretKey }, { ttl: new Date(Date.now() + RECIPE_TTL_MS), payFees: true });
|
|
122
|
+
const signed = await facade.signRecipe(recipe, keys.unshieldedKeystore.signDataAsync);
|
|
123
|
+
const finalized = await facade.finalizeRecipe(signed);
|
|
124
|
+
return facade.submitTransaction(finalized);
|
|
125
|
+
}
|
|
98
126
|
/**
|
|
99
127
|
* Register every NIGHT UTXO not yet registered for dust generation, so the
|
|
100
128
|
* wallet can pay transaction fees (fees are paid in DUST, which only
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/plumbing/wallet.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,8EAA8E;AAC9E,2EAA2E;AAC3E,oEAAoE;AACpE,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,GAGb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAA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M,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAChE,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,kBAAkB,EAAE,CAAC;QAChD,OAAO,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sig-net/midnight-contract-deploy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/sig-net/midnight-integration",
|
|
7
|
+
"directory": "packages/signet-contract-deploy"
|
|
8
|
+
},
|
|
4
9
|
"type": "module",
|
|
5
10
|
"description": "Deploy tooling for the central signet contract on Midnight: the operator deploy flow, the Node binding of @sig-net/midnight-contract to its compiled assets, and the generic deploy/wallet plumbing (node config, seed parsing, key derivation, wallet facade, unproven-tx build/submit) any Compact contract's deploy script composes.",
|
|
6
11
|
"//exports": "Local dev consumes raw TS source. `publishConfig.exports` below swaps this to the emitted ./dist at publish time, so npm consumers get JS + .d.ts while the monorepo keeps resolving to src.",
|
|
@@ -32,9 +37,9 @@
|
|
|
32
37
|
},
|
|
33
38
|
"dependencies": {
|
|
34
39
|
"@effect/platform-node": "^0.107.0",
|
|
35
|
-
"@midnight-ntwrk/compact-js": "2.5.5-rc.
|
|
36
|
-
"@midnight-ntwrk/compact-js-node": "2.5.5-rc.
|
|
37
|
-
"@midnight-ntwrk/midnight-js": "5.0.0-beta.
|
|
40
|
+
"@midnight-ntwrk/compact-js": "2.5.5-rc.6",
|
|
41
|
+
"@midnight-ntwrk/compact-js-node": "2.5.5-rc.6",
|
|
42
|
+
"@midnight-ntwrk/midnight-js": "5.0.0-beta.4",
|
|
38
43
|
"@midnight-ntwrk/platform-js": "^3.0.0",
|
|
39
44
|
"@midnightntwrk/ledger-v9": "1.0.0-rc.3",
|
|
40
45
|
"@midnightntwrk/wallet-sdk-abstractions": "3.0.0-beta.0",
|
|
@@ -45,8 +50,8 @@
|
|
|
45
50
|
"@midnightntwrk/wallet-sdk-shielded": "4.0.0-beta.2",
|
|
46
51
|
"@midnightntwrk/wallet-sdk-unshielded-wallet": "4.0.0-beta.2",
|
|
47
52
|
"@scure/bip39": "^2.2.0",
|
|
48
|
-
"@sig-net/midnight": "^0.0.
|
|
49
|
-
"@sig-net/midnight-contract": "^0.0.
|
|
53
|
+
"@sig-net/midnight": "^0.0.5",
|
|
54
|
+
"@sig-net/midnight-contract": "^0.0.5",
|
|
50
55
|
"effect": "^3.21.4"
|
|
51
56
|
},
|
|
52
57
|
"devDependencies": {
|