@openzeppelin/miden-multisig-client 0.18.0-rc.2 → 0.18.0-rc.3
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 +46 -4
- package/dist/account/builder.d.ts +3 -4
- package/dist/account/builder.d.ts.map +1 -1
- package/dist/account/builder.js +6 -13
- package/dist/account/builder.js.map +1 -1
- package/dist/client.d.ts +11 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8 -3
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +14 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/multisig.d.ts +40 -9
- package/dist/multisig.d.ts.map +1 -1
- package/dist/multisig.js +97 -108
- package/dist/multisig.js.map +1 -1
- package/dist/procedures.d.ts +5 -5
- package/dist/procedures.js +5 -5
- package/dist/recovery/proposalNoteImport.d.ts +5 -6
- package/dist/recovery/proposalNoteImport.d.ts.map +1 -1
- package/dist/recovery/proposalNoteImport.js +12 -13
- package/dist/recovery/proposalNoteImport.js.map +1 -1
- package/dist/recovery/publicNoteBackfill.d.ts +2 -3
- package/dist/recovery/publicNoteBackfill.d.ts.map +1 -1
- package/dist/recovery/publicNoteBackfill.js +4 -5
- package/dist/recovery/publicNoteBackfill.js.map +1 -1
- package/dist/transaction/authArgs.d.ts +2 -3
- package/dist/transaction/authArgs.d.ts.map +1 -1
- package/dist/transaction/authArgs.js +7 -14
- package/dist/transaction/authArgs.js.map +1 -1
- package/dist/transaction/consumeNotes.d.ts +4 -12
- package/dist/transaction/consumeNotes.d.ts.map +1 -1
- package/dist/transaction/consumeNotes.js +10 -4
- package/dist/transaction/consumeNotes.js.map +1 -1
- package/dist/transaction/noteAuthentication.d.ts +2 -3
- package/dist/transaction/noteAuthentication.d.ts.map +1 -1
- package/dist/transaction/noteAuthentication.js +11 -11
- package/dist/transaction/noteAuthentication.js.map +1 -1
- package/dist/transaction/options.d.ts +0 -7
- package/dist/transaction/options.d.ts.map +1 -1
- package/dist/transaction/p2id.d.ts +2 -3
- package/dist/transaction/p2id.d.ts.map +1 -1
- package/dist/transaction/p2id.js.map +1 -1
- package/dist/transaction/summary.d.ts +8 -14
- package/dist/transaction/summary.d.ts.map +1 -1
- package/dist/transaction/summary.js +64 -20
- package/dist/transaction/summary.js.map +1 -1
- package/dist/transaction/updateGuardian.d.ts +3 -7
- package/dist/transaction/updateGuardian.d.ts.map +1 -1
- package/dist/transaction/updateGuardian.js +3 -4
- package/dist/transaction/updateGuardian.js.map +1 -1
- package/dist/transaction/updateProcedureThreshold.d.ts +3 -8
- package/dist/transaction/updateProcedureThreshold.d.ts.map +1 -1
- package/dist/transaction/updateProcedureThreshold.js +3 -4
- package/dist/transaction/updateProcedureThreshold.js.map +1 -1
- package/dist/transaction/updateSigners.d.ts +3 -8
- package/dist/transaction/updateSigners.d.ts.map +1 -1
- package/dist/transaction/updateSigners.js +3 -4
- package/dist/transaction/updateSigners.js.map +1 -1
- package/package.json +4 -4
- package/src/account/builder.ts +6 -13
- package/src/client.ts +13 -10
- package/src/config.ts +14 -0
- package/src/index.ts +2 -3
- package/src/multisig.ts +125 -143
- package/src/procedures.ts +5 -5
- package/src/recovery/proposalNoteImport.ts +13 -15
- package/src/recovery/publicNoteBackfill.ts +6 -6
- package/src/transaction/authArgs.ts +15 -21
- package/src/transaction/consumeNotes.ts +6 -34
- package/src/transaction/noteAuthentication.ts +18 -13
- package/src/transaction/options.ts +0 -9
- package/src/transaction/p2id.ts +2 -3
- package/src/transaction/summary.ts +27 -69
- package/src/transaction/updateGuardian.ts +5 -23
- package/src/transaction/updateProcedureThreshold.ts +5 -25
- package/src/transaction/updateSigners.ts +5 -22
- package/dist/raw-client.d.ts +0 -14
- package/dist/raw-client.d.ts.map +0 -1
- package/dist/raw-client.js +0 -60
- package/dist/raw-client.js.map +0 -1
- package/src/raw-client.ts +0 -89
|
@@ -5,15 +5,13 @@ import {
|
|
|
5
5
|
Poseidon2,
|
|
6
6
|
TransactionRequest,
|
|
7
7
|
TransactionScript,
|
|
8
|
-
type WasmWebClient,
|
|
9
8
|
Word,
|
|
10
9
|
Word as WordType,
|
|
11
10
|
} from '@miden-sdk/miden-sdk';
|
|
12
11
|
import { getProcedureRoot, type ProcedureName } from '../procedures.js';
|
|
13
|
-
import { compileTxScript } from '../raw-client.js';
|
|
14
12
|
import { normalizeHexWord } from '../utils/encoding.js';
|
|
15
13
|
import { buildMultisigRequest, multisigRequestBuilder } from './authArgs.js';
|
|
16
|
-
import type {
|
|
14
|
+
import type { MultisigRequestOptions } from './options.js';
|
|
17
15
|
|
|
18
16
|
function buildProcedureThresholdFelts(procedure: ProcedureName, threshold: number): Felt[] {
|
|
19
17
|
const procedureRoot = WordType.fromHex(normalizeHexWord(getProcedureRoot(procedure)));
|
|
@@ -38,10 +36,9 @@ function buildProcedureThresholdConfigHash(procedure: ProcedureName, threshold:
|
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
async function buildUpdateProcedureThresholdScript(
|
|
41
|
-
client: MidenClient
|
|
39
|
+
client: MidenClient,
|
|
42
40
|
procedure: ProcedureName,
|
|
43
41
|
threshold: number,
|
|
44
|
-
midenRpcEndpoint?: string,
|
|
45
42
|
): Promise<TransactionScript> {
|
|
46
43
|
const procedureRoot = normalizeHexWord(getProcedureRoot(procedure));
|
|
47
44
|
|
|
@@ -58,35 +55,18 @@ pub proc main
|
|
|
58
55
|
end
|
|
59
56
|
`;
|
|
60
57
|
|
|
61
|
-
return
|
|
58
|
+
return client.compile.txScript({ code: scriptSource });
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
export function buildUpdateProcedureThresholdTransactionRequest(
|
|
65
|
-
client: MidenClient,
|
|
66
|
-
procedure: ProcedureName,
|
|
67
|
-
threshold: number,
|
|
68
|
-
options: MidenClientMultisigRequestOptions,
|
|
69
|
-
): Promise<{ request: TransactionRequest; salt: Word; configHash: Word }>;
|
|
70
|
-
export function buildUpdateProcedureThresholdTransactionRequest(
|
|
71
|
-
client: WasmWebClient,
|
|
72
|
-
procedure: ProcedureName,
|
|
73
|
-
threshold: number,
|
|
74
|
-
options: MultisigRequestOptions,
|
|
75
|
-
): Promise<{ request: TransactionRequest; salt: Word; configHash: Word }>;
|
|
76
61
|
export async function buildUpdateProcedureThresholdTransactionRequest(
|
|
77
|
-
client: MidenClient
|
|
62
|
+
client: MidenClient,
|
|
78
63
|
procedure: ProcedureName,
|
|
79
64
|
threshold: number,
|
|
80
65
|
options: MultisigRequestOptions,
|
|
81
66
|
): Promise<{ request: TransactionRequest; salt: Word; configHash: Word }> {
|
|
82
67
|
const configHash = buildProcedureThresholdConfigHash(procedure, threshold);
|
|
83
68
|
|
|
84
|
-
const script = await buildUpdateProcedureThresholdScript(
|
|
85
|
-
client,
|
|
86
|
-
procedure,
|
|
87
|
-
threshold,
|
|
88
|
-
options.midenRpcEndpoint,
|
|
89
|
-
);
|
|
69
|
+
const script = await buildUpdateProcedureThresholdScript(client, procedure, threshold);
|
|
90
70
|
const { builder, saltHex } = await multisigRequestBuilder(client, options);
|
|
91
71
|
let txBuilder = builder.withCustomScript(script);
|
|
92
72
|
|
|
@@ -6,15 +6,13 @@ import {
|
|
|
6
6
|
Poseidon2,
|
|
7
7
|
TransactionRequest,
|
|
8
8
|
TransactionScript,
|
|
9
|
-
type WasmWebClient,
|
|
10
9
|
Word,
|
|
11
10
|
Word as WordType,
|
|
12
11
|
} from '@miden-sdk/miden-sdk';
|
|
13
|
-
import { compileTxScript } from '../raw-client.js';
|
|
14
12
|
import { normalizeHexWord } from '../utils/encoding.js';
|
|
15
13
|
import { authSchemeId } from '../utils/signature.js';
|
|
16
14
|
import { buildMultisigRequest, multisigRequestBuilder } from './authArgs.js';
|
|
17
|
-
import type {
|
|
15
|
+
import type { MultisigRequestOptions } from './options.js';
|
|
18
16
|
import type { SignatureScheme } from '../types.js';
|
|
19
17
|
|
|
20
18
|
function buildMultisigConfigFelts(
|
|
@@ -56,10 +54,7 @@ export function buildMultisigConfigAdvice(
|
|
|
56
54
|
return { configHash, payload };
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
async function buildUpdateSignersScript(
|
|
60
|
-
client: MidenClient | WasmWebClient,
|
|
61
|
-
midenRpcEndpoint?: string,
|
|
62
|
-
): Promise<TransactionScript> {
|
|
57
|
+
async function buildUpdateSignersScript(client: MidenClient): Promise<TransactionScript> {
|
|
63
58
|
const scriptSource = `
|
|
64
59
|
use miden::standards::auth::multisig
|
|
65
60
|
|
|
@@ -69,23 +64,11 @@ pub proc main
|
|
|
69
64
|
end
|
|
70
65
|
`;
|
|
71
66
|
|
|
72
|
-
return
|
|
67
|
+
return client.compile.txScript({ code: scriptSource });
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
export function buildUpdateSignersTransactionRequest(
|
|
76
|
-
client: MidenClient,
|
|
77
|
-
threshold: number,
|
|
78
|
-
signerCommitments: string[],
|
|
79
|
-
options: MidenClientMultisigRequestOptions,
|
|
80
|
-
): Promise<{ request: TransactionRequest; salt: Word; configHash: Word }>;
|
|
81
|
-
export function buildUpdateSignersTransactionRequest(
|
|
82
|
-
client: WasmWebClient,
|
|
83
|
-
threshold: number,
|
|
84
|
-
signerCommitments: string[],
|
|
85
|
-
options: MultisigRequestOptions,
|
|
86
|
-
): Promise<{ request: TransactionRequest; salt: Word; configHash: Word }>;
|
|
87
70
|
export async function buildUpdateSignersTransactionRequest(
|
|
88
|
-
client: MidenClient
|
|
71
|
+
client: MidenClient,
|
|
89
72
|
threshold: number,
|
|
90
73
|
signerCommitments: string[],
|
|
91
74
|
options: MultisigRequestOptions,
|
|
@@ -112,7 +95,7 @@ export async function buildUpdateSignersTransactionRequest(
|
|
|
112
95
|
const advice = new AdviceMap();
|
|
113
96
|
advice.insert(configHashForAdvice, payload);
|
|
114
97
|
|
|
115
|
-
const script = await buildUpdateSignersScript(client
|
|
98
|
+
const script = await buildUpdateSignersScript(client);
|
|
116
99
|
|
|
117
100
|
const { builder, saltHex } = await multisigRequestBuilder(client, options);
|
|
118
101
|
let txBuilder = builder
|
package/dist/raw-client.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { MidenClient, type TransactionProver, type TransactionScript, WasmWebClient } from '@miden-sdk/miden-sdk';
|
|
2
|
-
export type RawClientSource = MidenClient | WasmWebClient;
|
|
3
|
-
export interface ScriptLibrarySource {
|
|
4
|
-
namespace: string;
|
|
5
|
-
code: string;
|
|
6
|
-
linking?: 'dynamic' | 'static';
|
|
7
|
-
}
|
|
8
|
-
export declare function requireConfigValue(field: string, value?: unknown): string;
|
|
9
|
-
export declare function requireMidenRpcEndpoint(endpoint?: string): string;
|
|
10
|
-
export declare function isPublicMidenClient(client: RawClientSource): client is MidenClient;
|
|
11
|
-
export declare function getRawMidenClient(client: RawClientSource, rpcUrl?: string): Promise<WasmWebClient>;
|
|
12
|
-
export declare function getTransactionProver(client: RawClientSource): TransactionProver | null;
|
|
13
|
-
export declare function compileTxScript(client: RawClientSource, code: string, libraries?: ScriptLibrarySource[], rpcUrl?: string): Promise<TransactionScript>;
|
|
14
|
-
//# sourceMappingURL=raw-client.d.ts.map
|
package/dist/raw-client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"raw-client.d.ts","sourceRoot":"","sources":["../src/raw-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,aAAa,EACd,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,aAAa,CAAC;AAC1D,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;CAChC;AAID,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CASzE;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,IAAI,WAAW,CAElF;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,eAAe,EACvB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,aAAa,CAAC,CAcxB;AAWD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,eAAe,GAAG,iBAAiB,GAAG,IAAI,CAEtF;AAED,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,mBAAmB,EAAO,EACrC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,CAgB5B"}
|
package/dist/raw-client.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { WasmWebClient, } from '@miden-sdk/miden-sdk';
|
|
2
|
-
const rawClientCache = new WeakMap();
|
|
3
|
-
export function requireConfigValue(field, value) {
|
|
4
|
-
if (typeof value !== 'string') {
|
|
5
|
-
throw new Error(`missing required configuration: ${field}`);
|
|
6
|
-
}
|
|
7
|
-
const normalizedValue = value.trim();
|
|
8
|
-
if (normalizedValue === '') {
|
|
9
|
-
throw new Error(`missing required configuration: ${field}`);
|
|
10
|
-
}
|
|
11
|
-
return normalizedValue;
|
|
12
|
-
}
|
|
13
|
-
export function requireMidenRpcEndpoint(endpoint) {
|
|
14
|
-
return requireConfigValue('midenRpcEndpoint', endpoint);
|
|
15
|
-
}
|
|
16
|
-
export function isPublicMidenClient(client) {
|
|
17
|
-
return 'accounts' in client && 'sync' in client;
|
|
18
|
-
}
|
|
19
|
-
export async function getRawMidenClient(client, rpcUrl) {
|
|
20
|
-
if (!isPublicMidenClient(client)) {
|
|
21
|
-
return client;
|
|
22
|
-
}
|
|
23
|
-
const cached = rawClientCache.get(client);
|
|
24
|
-
if (cached) {
|
|
25
|
-
return cached;
|
|
26
|
-
}
|
|
27
|
-
const endpoint = requireMidenRpcEndpoint(rpcUrl);
|
|
28
|
-
const rawClient = createRawClient(client, endpoint);
|
|
29
|
-
rawClientCache.set(client, rawClient);
|
|
30
|
-
return rawClient;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Opens the WASM client behind `client` on the same store. The protocol
|
|
34
|
-
* configuration comes from the node with every sync and is read from that
|
|
35
|
-
* shared store, so the shadow needs no fee faucet of its own.
|
|
36
|
-
*/
|
|
37
|
-
async function createRawClient(client, endpoint) {
|
|
38
|
-
return WasmWebClient.createClient(endpoint, undefined, undefined, await client.storeIdentifier());
|
|
39
|
-
}
|
|
40
|
-
export function getTransactionProver(client) {
|
|
41
|
-
return isPublicMidenClient(client) ? client.defaultProver : null;
|
|
42
|
-
}
|
|
43
|
-
export async function compileTxScript(client, code, libraries = [], rpcUrl) {
|
|
44
|
-
if (isPublicMidenClient(client)) {
|
|
45
|
-
return client.compile.txScript({ code, libraries });
|
|
46
|
-
}
|
|
47
|
-
const rawClient = await getRawMidenClient(client, rpcUrl);
|
|
48
|
-
const builder = await rawClient.createCodeBuilder();
|
|
49
|
-
for (const library of libraries) {
|
|
50
|
-
const builtLibrary = builder.buildLibrary(library.namespace, library.code);
|
|
51
|
-
if (library.linking === 'static') {
|
|
52
|
-
builder.linkStaticLibrary(builtLibrary);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
builder.linkDynamicLibrary(builtLibrary);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return builder.compileTxScript(code);
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=raw-client.js.map
|
package/dist/raw-client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"raw-client.js","sourceRoot":"","sources":["../src/raw-client.ts"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,
|
|
3
|
-
type TransactionProver,
|
|
4
|
-
type TransactionScript,
|
|
5
|
-
WasmWebClient,
|
|
6
|
-
} from '@miden-sdk/miden-sdk';
|
|
7
|
-
|
|
8
|
-
export type RawClientSource = MidenClient | WasmWebClient;
|
|
9
|
-
export interface ScriptLibrarySource {
|
|
10
|
-
namespace: string;
|
|
11
|
-
code: string;
|
|
12
|
-
linking?: 'dynamic' | 'static';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const rawClientCache = new WeakMap<MidenClient, Promise<WasmWebClient>>();
|
|
16
|
-
|
|
17
|
-
export function requireConfigValue(field: string, value?: unknown): string {
|
|
18
|
-
if (typeof value !== 'string') {
|
|
19
|
-
throw new Error(`missing required configuration: ${field}`);
|
|
20
|
-
}
|
|
21
|
-
const normalizedValue = value.trim();
|
|
22
|
-
if (normalizedValue === '') {
|
|
23
|
-
throw new Error(`missing required configuration: ${field}`);
|
|
24
|
-
}
|
|
25
|
-
return normalizedValue;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function requireMidenRpcEndpoint(endpoint?: string): string {
|
|
29
|
-
return requireConfigValue('midenRpcEndpoint', endpoint);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function isPublicMidenClient(client: RawClientSource): client is MidenClient {
|
|
33
|
-
return 'accounts' in client && 'sync' in client;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function getRawMidenClient(
|
|
37
|
-
client: RawClientSource,
|
|
38
|
-
rpcUrl?: string,
|
|
39
|
-
): Promise<WasmWebClient> {
|
|
40
|
-
if (!isPublicMidenClient(client)) {
|
|
41
|
-
return client;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const cached = rawClientCache.get(client);
|
|
45
|
-
if (cached) {
|
|
46
|
-
return cached;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const endpoint = requireMidenRpcEndpoint(rpcUrl);
|
|
50
|
-
const rawClient = createRawClient(client, endpoint);
|
|
51
|
-
rawClientCache.set(client, rawClient);
|
|
52
|
-
return rawClient;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Opens the WASM client behind `client` on the same store. The protocol
|
|
57
|
-
* configuration comes from the node with every sync and is read from that
|
|
58
|
-
* shared store, so the shadow needs no fee faucet of its own.
|
|
59
|
-
*/
|
|
60
|
-
async function createRawClient(client: MidenClient, endpoint: string): Promise<WasmWebClient> {
|
|
61
|
-
return WasmWebClient.createClient(endpoint, undefined, undefined, await client.storeIdentifier());
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function getTransactionProver(client: RawClientSource): TransactionProver | null {
|
|
65
|
-
return isPublicMidenClient(client) ? client.defaultProver : null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function compileTxScript(
|
|
69
|
-
client: RawClientSource,
|
|
70
|
-
code: string,
|
|
71
|
-
libraries: ScriptLibrarySource[] = [],
|
|
72
|
-
rpcUrl?: string,
|
|
73
|
-
): Promise<TransactionScript> {
|
|
74
|
-
if (isPublicMidenClient(client)) {
|
|
75
|
-
return client.compile.txScript({ code, libraries });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const rawClient = await getRawMidenClient(client, rpcUrl);
|
|
79
|
-
const builder = await rawClient.createCodeBuilder();
|
|
80
|
-
for (const library of libraries) {
|
|
81
|
-
const builtLibrary = builder.buildLibrary(library.namespace, library.code);
|
|
82
|
-
if (library.linking === 'static') {
|
|
83
|
-
builder.linkStaticLibrary(builtLibrary);
|
|
84
|
-
} else {
|
|
85
|
-
builder.linkDynamicLibrary(builtLibrary);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return builder.compileTxScript(code);
|
|
89
|
-
}
|