@midnight-ntwrk/midnight-js-types 3.0.0 → 3.1.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/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.cjs +91 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +155 -4
- package/dist/index.d.mts +155 -4
- package/dist/index.d.ts +155 -4
- package/dist/index.mjs +73 -2
- package/dist/index.mjs.map +1 -1
- package/dist/private-state-provider.d.ts +113 -0
- package/dist/private-state-provider.d.ts.map +1 -1
- package/package.json +2 -3
package/dist/errors.d.ts
CHANGED
|
@@ -10,4 +10,42 @@ export declare class InvalidProtocolSchemeError extends Error {
|
|
|
10
10
|
*/
|
|
11
11
|
constructor(invalidScheme: string, allowableSchemes: string[]);
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* An error thrown when exporting private states fails.
|
|
15
|
+
*/
|
|
16
|
+
export declare class PrivateStateExportError extends Error {
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Cause types for private state import errors.
|
|
21
|
+
*/
|
|
22
|
+
export type PrivateStateImportErrorCause = 'decryption_failed' | 'invalid_format' | 'conflict' | 'unknown';
|
|
23
|
+
/**
|
|
24
|
+
* Base error thrown when importing private states fails.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PrivateStateImportError extends Error {
|
|
27
|
+
readonly cause?: PrivateStateImportErrorCause | undefined;
|
|
28
|
+
constructor(message: string, cause?: PrivateStateImportErrorCause | undefined);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Error thrown when decryption of export data fails.
|
|
32
|
+
* This could be due to wrong password, corrupted data, or tampered content.
|
|
33
|
+
* The specific cause is intentionally not disclosed to prevent oracle attacks.
|
|
34
|
+
*/
|
|
35
|
+
export declare class ExportDecryptionError extends PrivateStateImportError {
|
|
36
|
+
constructor();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Error thrown when the export data format is invalid.
|
|
40
|
+
*/
|
|
41
|
+
export declare class InvalidExportFormatError extends PrivateStateImportError {
|
|
42
|
+
constructor(message?: string);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Error thrown when import conflicts with existing data and conflictStrategy is 'error'.
|
|
46
|
+
*/
|
|
47
|
+
export declare class ImportConflictError extends PrivateStateImportError {
|
|
48
|
+
readonly conflictCount: number;
|
|
49
|
+
constructor(conflictCount: number);
|
|
50
|
+
}
|
|
13
51
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;aAMjC,aAAa,EAAE,MAAM;aACrB,gBAAgB,EAAE,MAAM,EAAE;IAN5C;;;OAGG;gBAEe,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,MAAM,EAAE;CAI7C"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;aAMjC,aAAa,EAAE,MAAM;aACrB,gBAAgB,EAAE,MAAM,EAAE;IAN5C;;;OAGG;gBAEe,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,MAAM,EAAE;CAI7C;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACpC,mBAAmB,GACnB,gBAAgB,GAChB,UAAU,GACV,SAAS,CAAC;AAEd;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;aAG9B,KAAK,CAAC,EAAE,4BAA4B;gBADpD,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,4BAA4B,YAAA;CAKvD;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,uBAAuB;;CAQjE;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,uBAAuB;gBACvD,OAAO,SAA0B;CAI9C;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,uBAAuB;aAClC,aAAa,EAAE,MAAM;gBAArB,aAAa,EAAE,MAAM;CAOlD"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var effect
|
|
3
|
+
var effect = require('@midnight-ntwrk/compact-js/effect');
|
|
4
4
|
var platformJs = require('@midnight-ntwrk/platform-js');
|
|
5
5
|
var Configuration = require('@midnight-ntwrk/platform-js/effect/Configuration');
|
|
6
|
-
var effect = require('effect');
|
|
6
|
+
var effect$1 = require('effect');
|
|
7
7
|
var ledgerV7 = require('@midnight-ntwrk/ledger-v7');
|
|
8
8
|
|
|
9
9
|
function _interopNamespaceDefault(e) {
|
|
@@ -48,21 +48,21 @@ var Configuration__namespace = /*#__PURE__*/_interopNamespaceDefault(Configurati
|
|
|
48
48
|
*
|
|
49
49
|
* @internal
|
|
50
50
|
*/
|
|
51
|
-
const makeAdaptedReader = (zkConfigProvider) => (compiledContract) => effect.Effect.gen(function* () {
|
|
51
|
+
const makeAdaptedReader = (zkConfigProvider) => (compiledContract) => effect$1.Effect.gen(function* () {
|
|
52
52
|
// TODO: Consider implementing the logic used in Compact.js (look at the contract manifest to determine
|
|
53
53
|
// if the circuit is verifiable). See PM-21376.
|
|
54
|
-
const getVerifierKey = (impureCircuitId) => effect.Effect.tryPromise({
|
|
55
|
-
try: () => zkConfigProvider.getVerifierKey(impureCircuitId).then((verifierKey) => effect.Option.some(effect
|
|
56
|
-
catch: (err) => effect
|
|
54
|
+
const getVerifierKey = (impureCircuitId) => effect$1.Effect.tryPromise({
|
|
55
|
+
try: () => zkConfigProvider.getVerifierKey(impureCircuitId).then((verifierKey) => effect$1.Option.some(effect.Contract.VerifierKey(verifierKey))),
|
|
56
|
+
catch: (err) => effect.ZKConfigurationReadError.make(compiledContract.tag, impureCircuitId, 'verifier-key', err)
|
|
57
57
|
});
|
|
58
58
|
return {
|
|
59
59
|
getVerifierKey,
|
|
60
|
-
getVerifierKeys: (impureCircuitIds) => effect.Effect.forEach(impureCircuitIds, (impureCircuitId) => getVerifierKey(impureCircuitId).pipe(effect.Effect.map((verifierKey) => [impureCircuitId, verifierKey])), { concurrency: 'unbounded', discard: false })
|
|
60
|
+
getVerifierKeys: (impureCircuitIds) => effect$1.Effect.forEach(impureCircuitIds, (impureCircuitId) => getVerifierKey(impureCircuitId).pipe(effect$1.Effect.map((verifierKey) => [impureCircuitId, verifierKey])), { concurrency: 'unbounded', discard: false })
|
|
61
61
|
};
|
|
62
62
|
});
|
|
63
|
-
const makeAdaptedRuntimeLayer = (zkConfigProvider, configMap) => effect.Layer.mergeAll(effect.Layer.succeed(effect
|
|
63
|
+
const makeAdaptedRuntimeLayer = (zkConfigProvider, configMap) => effect$1.Layer.mergeAll(effect$1.Layer.succeed(effect.ZKConfiguration.ZKConfiguration, effect.ZKConfiguration.ZKConfiguration.of({
|
|
64
64
|
createReader: makeAdaptedReader(zkConfigProvider)
|
|
65
|
-
})), Configuration__namespace.layer).pipe(effect.Layer.provide(effect.Layer.setConfigProvider(effect.ConfigProvider.fromMap(configMap, { pathDelim: '_' }).pipe(effect.ConfigProvider.constantCase))));
|
|
65
|
+
})), Configuration__namespace.layer).pipe(effect$1.Layer.provide(effect$1.Layer.setConfigProvider(effect$1.ConfigProvider.fromMap(configMap, { pathDelim: '_' }).pipe(effect$1.ConfigProvider.constantCase))));
|
|
66
66
|
/**
|
|
67
67
|
* Constructs an Effect managed runtime configured to execute contract executables.
|
|
68
68
|
*
|
|
@@ -75,7 +75,7 @@ const makeContractExecutableRuntime = (zkConfigProvider, options) => {
|
|
|
75
75
|
if (options.signingKey) {
|
|
76
76
|
config = config.concat([['KEYS_SIGNING', options.signingKey]]);
|
|
77
77
|
}
|
|
78
|
-
return effect
|
|
78
|
+
return effect.ContractExecutableRuntime.make(makeAdaptedRuntimeLayer(zkConfigProvider, new Map(config)));
|
|
79
79
|
};
|
|
80
80
|
/**
|
|
81
81
|
* Unwraps an Effect `Exit` instance, returning its value if it is successful, or throwing the error contained
|
|
@@ -84,12 +84,12 @@ const makeContractExecutableRuntime = (zkConfigProvider, options) => {
|
|
|
84
84
|
* @param exit The source Effect `Exit` instance.
|
|
85
85
|
* @returns The value from `exit` if it is successful, otherwise throws the error contained within it.
|
|
86
86
|
*/
|
|
87
|
-
const exitResultOrError = (exit) => effect.Exit.match(exit, {
|
|
87
|
+
const exitResultOrError = (exit) => effect$1.Exit.match(exit, {
|
|
88
88
|
onSuccess: (a) => a,
|
|
89
89
|
onFailure: (cause) => {
|
|
90
|
-
if (effect.Cause.isFailType(cause))
|
|
90
|
+
if (effect$1.Cause.isFailType(cause))
|
|
91
91
|
throw cause.error;
|
|
92
|
-
throw new Error(`Unexpected error: ${effect.Cause.pretty(cause)}`);
|
|
92
|
+
throw new Error(`Unexpected error: ${effect$1.Cause.pretty(cause)}`);
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
/**
|
|
@@ -99,7 +99,7 @@ const exitResultOrError = (exit) => effect.Exit.match(exit, {
|
|
|
99
99
|
* @returns An `Option.some` for `obj`.
|
|
100
100
|
*/
|
|
101
101
|
const asEffectOption = (obj) => {
|
|
102
|
-
return effect.Option.some(obj);
|
|
102
|
+
return effect$1.Option.some(obj);
|
|
103
103
|
};
|
|
104
104
|
/**
|
|
105
105
|
* Constructs a branded contract address from a given string value.
|
|
@@ -139,6 +139,57 @@ class InvalidProtocolSchemeError extends Error {
|
|
|
139
139
|
this.allowableSchemes = allowableSchemes;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* An error thrown when exporting private states fails.
|
|
144
|
+
*/
|
|
145
|
+
class PrivateStateExportError extends Error {
|
|
146
|
+
constructor(message) {
|
|
147
|
+
super(message);
|
|
148
|
+
this.name = 'PrivateStateExportError';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Base error thrown when importing private states fails.
|
|
153
|
+
*/
|
|
154
|
+
class PrivateStateImportError extends Error {
|
|
155
|
+
cause;
|
|
156
|
+
constructor(message, cause) {
|
|
157
|
+
super(message);
|
|
158
|
+
this.cause = cause;
|
|
159
|
+
this.name = 'PrivateStateImportError';
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Error thrown when decryption of export data fails.
|
|
164
|
+
* This could be due to wrong password, corrupted data, or tampered content.
|
|
165
|
+
* The specific cause is intentionally not disclosed to prevent oracle attacks.
|
|
166
|
+
*/
|
|
167
|
+
class ExportDecryptionError extends PrivateStateImportError {
|
|
168
|
+
constructor() {
|
|
169
|
+
super('Failed to decrypt export data. The password may be incorrect or the data may be corrupted.', 'decryption_failed');
|
|
170
|
+
this.name = 'ExportDecryptionError';
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Error thrown when the export data format is invalid.
|
|
175
|
+
*/
|
|
176
|
+
class InvalidExportFormatError extends PrivateStateImportError {
|
|
177
|
+
constructor(message = 'Invalid export format') {
|
|
178
|
+
super(message, 'invalid_format');
|
|
179
|
+
this.name = 'InvalidExportFormatError';
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Error thrown when import conflicts with existing data and conflictStrategy is 'error'.
|
|
184
|
+
*/
|
|
185
|
+
class ImportConflictError extends PrivateStateImportError {
|
|
186
|
+
conflictCount;
|
|
187
|
+
constructor(conflictCount) {
|
|
188
|
+
super(`Import conflicts with ${conflictCount} existing private state${conflictCount === 1 ? '' : 's'}`, 'conflict');
|
|
189
|
+
this.conflictCount = conflictCount;
|
|
190
|
+
this.name = 'ImportConflictError';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
142
193
|
|
|
143
194
|
/*
|
|
144
195
|
* This file is part of midnight-js.
|
|
@@ -248,6 +299,26 @@ const FailFallible = 'FailFallible';
|
|
|
248
299
|
*/
|
|
249
300
|
const SucceedEntirely = 'SucceedEntirely';
|
|
250
301
|
|
|
302
|
+
/*
|
|
303
|
+
* This file is part of midnight-js.
|
|
304
|
+
* Copyright (C) 2025 Midnight Foundation
|
|
305
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
306
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
307
|
+
* You may not use this file except in compliance with the License.
|
|
308
|
+
* You may obtain a copy of the License at
|
|
309
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
310
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
311
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
312
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
313
|
+
* See the License for the specific language governing permissions and
|
|
314
|
+
* limitations under the License.
|
|
315
|
+
*/
|
|
316
|
+
/**
|
|
317
|
+
* Maximum number of states that can be exported/imported.
|
|
318
|
+
* This limit prevents memory exhaustion attacks.
|
|
319
|
+
*/
|
|
320
|
+
const MAX_EXPORT_STATES = 10000;
|
|
321
|
+
|
|
251
322
|
/*
|
|
252
323
|
* This file is part of midnight-js.
|
|
253
324
|
* Copyright (C) 2025 Midnight Foundation
|
|
@@ -301,9 +372,15 @@ Object.defineProperty(exports, "Transaction", {
|
|
|
301
372
|
enumerable: true,
|
|
302
373
|
get: function () { return ledgerV7.Transaction; }
|
|
303
374
|
});
|
|
375
|
+
exports.ExportDecryptionError = ExportDecryptionError;
|
|
304
376
|
exports.FailEntirely = FailEntirely;
|
|
305
377
|
exports.FailFallible = FailFallible;
|
|
378
|
+
exports.ImportConflictError = ImportConflictError;
|
|
379
|
+
exports.InvalidExportFormatError = InvalidExportFormatError;
|
|
306
380
|
exports.InvalidProtocolSchemeError = InvalidProtocolSchemeError;
|
|
381
|
+
exports.MAX_EXPORT_STATES = MAX_EXPORT_STATES;
|
|
382
|
+
exports.PrivateStateExportError = PrivateStateExportError;
|
|
383
|
+
exports.PrivateStateImportError = PrivateStateImportError;
|
|
307
384
|
exports.SegmentFail = SegmentFail;
|
|
308
385
|
exports.SegmentSuccess = SegmentSuccess;
|
|
309
386
|
exports.SucceedEntirely = SucceedEntirely;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/contract.ts","../src/errors.ts","../src/logger-provider.ts","../src/midnight-types.ts","../src/zk-config-provider.ts"],"sourcesContent":[null,null,null,null,null],"names":["Effect","Option","Contract","ZKConfigurationReadError","Layer","ZKConfiguration","Configuration","ConfigProvider","ContractExecutableRuntime","Exit","Cause","ContractAddress","LogLevel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;AAaG;AAWH;;;;;;;;AAQG;AACH,MAAM,iBAAiB,GAAG,CAAsC,gBAA0C,KACxG,CAAC,gBAA0D,KACzDA,
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/contract.ts","../src/errors.ts","../src/logger-provider.ts","../src/midnight-types.ts","../src/private-state-provider.ts","../src/zk-config-provider.ts"],"sourcesContent":[null,null,null,null,null,null],"names":["Effect","Option","Contract","ZKConfigurationReadError","Layer","ZKConfiguration","Configuration","ConfigProvider","ContractExecutableRuntime","Exit","Cause","ContractAddress","LogLevel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;AAaG;AAWH;;;;;;;;AAQG;AACH,MAAM,iBAAiB,GAAG,CAAsC,gBAA0C,KACxG,CAAC,gBAA0D,KACzDA,eAAM,CAAC,GAAG,CAAC,aAAS;;;IAGlB,MAAM,cAAc,GAAG,CAAC,eAA4C,KAClEA,eAAM,CAAC,UAAU,CAAC;AAChB,QAAA,GAAG,EAAE,MAAM,gBAA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;;;;AAMG;MACmB,gBAAgB,CAAA;AAmBpC;;;AAGG;IACH,MAAM,eAAe,CAAC,UAAe,EAAA;AACnC,QAAA,OAAO,OAAO,CAAC,GAAG,CAChB,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,KAAI;YAC1B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;AACzC,YAAA,OAAO,CAAC,EAAE,EAAE,GAAG,CAAC;QAClB,CAAC,CAAC,CACH;IACH;AAEA;;;AAGG;IACH,MAAM,GAAG,CAAC,SAAY,EAAA;QACpB,OAAO;YACL,SAAS;AACT,YAAA,SAAS,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC;AAC7C,YAAA,WAAW,EAAE,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC;AACjD,YAAA,IAAI,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS;SACnC;IACH;IAEA,qBAAqB,GAAA;AACnB,QAAA,OAAO,IAA2B;IACpC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ContractExecutable } from '@midnight-ntwrk/compact-js/effect';
|
|
2
2
|
import { ContractAddress as ContractAddress$1 } from '@midnight-ntwrk/platform-js';
|
|
3
|
-
import {
|
|
3
|
+
import { Option, Exit, ConfigError } from 'effect';
|
|
4
4
|
import { ManagedRuntime } from 'effect/ManagedRuntime';
|
|
5
|
-
import {
|
|
5
|
+
import { Transaction, SignatureEnabled, Proof, Binding, TransactionId, TransactionHash, ContractAddress, IntentHash, RawTokenType, FinalizedTransaction, UnprovenTransaction, PreBinding, ZswapChainState, CoinPublicKey, EncPublicKey } from '@midnight-ntwrk/ledger-v7';
|
|
6
6
|
export { Transaction } from '@midnight-ntwrk/ledger-v7';
|
|
7
7
|
import { LogFn } from 'pino';
|
|
8
8
|
import { ContractAddress as ContractAddress$2, SigningKey, ContractState } from '@midnight-ntwrk/compact-runtime';
|
|
@@ -356,6 +356,44 @@ declare class InvalidProtocolSchemeError extends Error {
|
|
|
356
356
|
*/
|
|
357
357
|
constructor(invalidScheme: string, allowableSchemes: string[]);
|
|
358
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* An error thrown when exporting private states fails.
|
|
361
|
+
*/
|
|
362
|
+
declare class PrivateStateExportError extends Error {
|
|
363
|
+
constructor(message: string);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Cause types for private state import errors.
|
|
367
|
+
*/
|
|
368
|
+
type PrivateStateImportErrorCause = 'decryption_failed' | 'invalid_format' | 'conflict' | 'unknown';
|
|
369
|
+
/**
|
|
370
|
+
* Base error thrown when importing private states fails.
|
|
371
|
+
*/
|
|
372
|
+
declare class PrivateStateImportError extends Error {
|
|
373
|
+
readonly cause?: PrivateStateImportErrorCause | undefined;
|
|
374
|
+
constructor(message: string, cause?: PrivateStateImportErrorCause | undefined);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Error thrown when decryption of export data fails.
|
|
378
|
+
* This could be due to wrong password, corrupted data, or tampered content.
|
|
379
|
+
* The specific cause is intentionally not disclosed to prevent oracle attacks.
|
|
380
|
+
*/
|
|
381
|
+
declare class ExportDecryptionError extends PrivateStateImportError {
|
|
382
|
+
constructor();
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Error thrown when the export data format is invalid.
|
|
386
|
+
*/
|
|
387
|
+
declare class InvalidExportFormatError extends PrivateStateImportError {
|
|
388
|
+
constructor(message?: string);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Error thrown when import conflicts with existing data and conflictStrategy is 'error'.
|
|
392
|
+
*/
|
|
393
|
+
declare class ImportConflictError extends PrivateStateImportError {
|
|
394
|
+
readonly conflictCount: number;
|
|
395
|
+
constructor(conflictCount: number);
|
|
396
|
+
}
|
|
359
397
|
|
|
360
398
|
/**
|
|
361
399
|
* A valid named log level.
|
|
@@ -403,6 +441,90 @@ interface MidnightProvider {
|
|
|
403
441
|
* A type representing an ID used to store a contract's private state.
|
|
404
442
|
*/
|
|
405
443
|
type PrivateStateId = string;
|
|
444
|
+
/**
|
|
445
|
+
* Represents the exported private state data structure.
|
|
446
|
+
* All metadata is included in the encrypted payload to prevent tampering.
|
|
447
|
+
*/
|
|
448
|
+
interface PrivateStateExport {
|
|
449
|
+
/**
|
|
450
|
+
* Format identifier. Must be 'midnight-private-state-export'.
|
|
451
|
+
*/
|
|
452
|
+
readonly format: 'midnight-private-state-export';
|
|
453
|
+
/**
|
|
454
|
+
* Encrypted payload containing version, metadata, and serialized private states.
|
|
455
|
+
* Format: base64-encoded AES-256-GCM encrypted JSON.
|
|
456
|
+
*/
|
|
457
|
+
readonly encryptedPayload: string;
|
|
458
|
+
/**
|
|
459
|
+
* Salt used for key derivation (hex-encoded, 32 bytes / 64 characters).
|
|
460
|
+
* Required for decryption with the export password.
|
|
461
|
+
*/
|
|
462
|
+
readonly salt: string;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Maximum number of states that can be exported/imported.
|
|
466
|
+
* This limit prevents memory exhaustion attacks.
|
|
467
|
+
*/
|
|
468
|
+
declare const MAX_EXPORT_STATES = 10000;
|
|
469
|
+
/**
|
|
470
|
+
* Options for exporting private states.
|
|
471
|
+
*/
|
|
472
|
+
interface ExportPrivateStatesOptions {
|
|
473
|
+
/**
|
|
474
|
+
* Password used to encrypt the export.
|
|
475
|
+
* Must be at least 16 characters.
|
|
476
|
+
* If not provided, uses the storage password.
|
|
477
|
+
*/
|
|
478
|
+
readonly password?: string;
|
|
479
|
+
/**
|
|
480
|
+
* Maximum number of states to export.
|
|
481
|
+
* Defaults to MAX_EXPORT_STATES (10000).
|
|
482
|
+
* Set to a lower value to limit memory usage.
|
|
483
|
+
*/
|
|
484
|
+
readonly maxStates?: number;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Options for importing private states.
|
|
488
|
+
*/
|
|
489
|
+
interface ImportPrivateStatesOptions {
|
|
490
|
+
/**
|
|
491
|
+
* Password used to decrypt the import.
|
|
492
|
+
* Must match the password used during export.
|
|
493
|
+
* If not provided, uses the storage password.
|
|
494
|
+
*/
|
|
495
|
+
readonly password?: string;
|
|
496
|
+
/**
|
|
497
|
+
* How to handle conflicts when a private state ID already exists.
|
|
498
|
+
* - 'skip': Keep existing state, ignore imported state
|
|
499
|
+
* - 'overwrite': Replace existing state with imported state
|
|
500
|
+
* - 'error': Throw an error if any conflict is detected
|
|
501
|
+
* Default: 'error'
|
|
502
|
+
*/
|
|
503
|
+
readonly conflictStrategy?: 'skip' | 'overwrite' | 'error';
|
|
504
|
+
/**
|
|
505
|
+
* Maximum number of states to import.
|
|
506
|
+
* Defaults to MAX_EXPORT_STATES (10000).
|
|
507
|
+
* Set to a lower value to limit memory usage.
|
|
508
|
+
*/
|
|
509
|
+
readonly maxStates?: number;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Result of an import operation.
|
|
513
|
+
*/
|
|
514
|
+
interface ImportPrivateStatesResult {
|
|
515
|
+
/**
|
|
516
|
+
* Number of states successfully imported.
|
|
517
|
+
*/
|
|
518
|
+
readonly imported: number;
|
|
519
|
+
/**
|
|
520
|
+
* Number of states skipped due to conflicts (when conflictStrategy is 'skip').
|
|
521
|
+
*/
|
|
522
|
+
readonly skipped: number;
|
|
523
|
+
/**
|
|
524
|
+
* Number of states that overwrote existing states (when conflictStrategy is 'overwrite').
|
|
525
|
+
*/
|
|
526
|
+
readonly overwritten: number;
|
|
527
|
+
}
|
|
406
528
|
/**
|
|
407
529
|
* Interface for a typed key-valued store containing contract private states.
|
|
408
530
|
*
|
|
@@ -410,6 +532,14 @@ type PrivateStateId = string;
|
|
|
410
532
|
* @typeParam PS - Parameter indicating the private state type stored, sometimes a union of private state types.
|
|
411
533
|
*/
|
|
412
534
|
interface PrivateStateProvider<PSI extends PrivateStateId = PrivateStateId, PS = any> {
|
|
535
|
+
/**
|
|
536
|
+
* Set the contract address for scoping private state operations.
|
|
537
|
+
* Must be called before any get/set/remove operations on private states.
|
|
538
|
+
* This provides namespace isolation between different contracts.
|
|
539
|
+
*
|
|
540
|
+
* @param address The contract address to scope operations to.
|
|
541
|
+
*/
|
|
542
|
+
setContractAddress(address: ContractAddress$2): void;
|
|
413
543
|
/**
|
|
414
544
|
* Store the given private state at the given private state ID.
|
|
415
545
|
*
|
|
@@ -456,6 +586,27 @@ interface PrivateStateProvider<PSI extends PrivateStateId = PrivateStateId, PS =
|
|
|
456
586
|
* Remove all contract signing keys.
|
|
457
587
|
*/
|
|
458
588
|
clearSigningKeys(): Promise<void>;
|
|
589
|
+
/**
|
|
590
|
+
* Export all private states as an encrypted JSON-serializable structure.
|
|
591
|
+
*
|
|
592
|
+
* NOTE: This does NOT export signing keys for security reasons.
|
|
593
|
+
*
|
|
594
|
+
* @param options Export options including optional custom password and state limit.
|
|
595
|
+
* @returns A JSON-serializable export structure that can be saved or transmitted.
|
|
596
|
+
* @throws {PrivateStateExportError} If no states exist to export or limit exceeded.
|
|
597
|
+
*/
|
|
598
|
+
exportPrivateStates(options?: ExportPrivateStatesOptions): Promise<PrivateStateExport>;
|
|
599
|
+
/**
|
|
600
|
+
* Import private states from a previously exported structure.
|
|
601
|
+
*
|
|
602
|
+
* @param exportData The export data structure to import.
|
|
603
|
+
* @param options Import options including password, conflict strategy, and state limit.
|
|
604
|
+
* @returns Result indicating how many states were imported/skipped/overwritten.
|
|
605
|
+
* @throws {ExportDecryptionError} If decryption fails (wrong password or corrupted data).
|
|
606
|
+
* @throws {InvalidExportFormatError} If the export format is invalid or unsupported.
|
|
607
|
+
* @throws {ImportConflictError} If conflictStrategy is 'error' and conflicts exist.
|
|
608
|
+
*/
|
|
609
|
+
importPrivateStates(exportData: PrivateStateExport, options?: ImportPrivateStatesOptions): Promise<ImportPrivateStatesResult>;
|
|
459
610
|
}
|
|
460
611
|
|
|
461
612
|
type UnboundTransaction = Transaction<SignatureEnabled, Proof, PreBinding>;
|
|
@@ -695,5 +846,5 @@ interface MidnightProviders<ICK extends Contract.ImpureCircuitId<Contract.Any> =
|
|
|
695
846
|
readonly loggerProvider?: LoggerProvider;
|
|
696
847
|
}
|
|
697
848
|
|
|
698
|
-
export { FailEntirely, FailFallible, InvalidProtocolSchemeError, LogLevel, SegmentFail, SegmentSuccess, SucceedEntirely, ZKConfigProvider, asContractAddress, asEffectOption, createProverKey, createVerifierKey, createZKIR, exitResultOrError, makeContractExecutableRuntime, zkConfigToProvingKeyMaterial };
|
|
699
|
-
export type { All, BlockHash, BlockHashConfig, BlockHeightConfig, ContractExecutableRuntimeOptions, ContractStateObservableConfig, Fees, FinalizedTxData, KeyMaterialProvider, Latest, LoggerProvider, MidnightProvider, MidnightProviders, PrivateStateId, PrivateStateProvider, ProofProvider, ProveTxConfig, ProverKey, PublicDataProvider, SegmentStatus, TxIdConfig, TxStatus, UnboundTransaction, UnshieldedBalance, UnshieldedBalances, UnshieldedUtxo, UnshieldedUtxos, VerifierKey, WalletProvider, ZKConfig, ZKIR };
|
|
849
|
+
export { ExportDecryptionError, FailEntirely, FailFallible, ImportConflictError, InvalidExportFormatError, InvalidProtocolSchemeError, LogLevel, MAX_EXPORT_STATES, PrivateStateExportError, PrivateStateImportError, SegmentFail, SegmentSuccess, SucceedEntirely, ZKConfigProvider, asContractAddress, asEffectOption, createProverKey, createVerifierKey, createZKIR, exitResultOrError, makeContractExecutableRuntime, zkConfigToProvingKeyMaterial };
|
|
850
|
+
export type { All, BlockHash, BlockHashConfig, BlockHeightConfig, ContractExecutableRuntimeOptions, ContractStateObservableConfig, ExportPrivateStatesOptions, Fees, FinalizedTxData, ImportPrivateStatesOptions, ImportPrivateStatesResult, KeyMaterialProvider, Latest, LoggerProvider, MidnightProvider, MidnightProviders, PrivateStateExport, PrivateStateId, PrivateStateImportErrorCause, PrivateStateProvider, ProofProvider, ProveTxConfig, ProverKey, PublicDataProvider, SegmentStatus, TxIdConfig, TxStatus, UnboundTransaction, UnshieldedBalance, UnshieldedBalances, UnshieldedUtxo, UnshieldedUtxos, VerifierKey, WalletProvider, ZKConfig, ZKIR };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ContractExecutable } from '@midnight-ntwrk/compact-js/effect';
|
|
2
2
|
import { ContractAddress as ContractAddress$1 } from '@midnight-ntwrk/platform-js';
|
|
3
|
-
import {
|
|
3
|
+
import { Option, Exit, ConfigError } from 'effect';
|
|
4
4
|
import { ManagedRuntime } from 'effect/ManagedRuntime';
|
|
5
|
-
import {
|
|
5
|
+
import { Transaction, SignatureEnabled, Proof, Binding, TransactionId, TransactionHash, ContractAddress, IntentHash, RawTokenType, FinalizedTransaction, UnprovenTransaction, PreBinding, ZswapChainState, CoinPublicKey, EncPublicKey } from '@midnight-ntwrk/ledger-v7';
|
|
6
6
|
export { Transaction } from '@midnight-ntwrk/ledger-v7';
|
|
7
7
|
import { LogFn } from 'pino';
|
|
8
8
|
import { ContractAddress as ContractAddress$2, SigningKey, ContractState } from '@midnight-ntwrk/compact-runtime';
|
|
@@ -356,6 +356,44 @@ declare class InvalidProtocolSchemeError extends Error {
|
|
|
356
356
|
*/
|
|
357
357
|
constructor(invalidScheme: string, allowableSchemes: string[]);
|
|
358
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* An error thrown when exporting private states fails.
|
|
361
|
+
*/
|
|
362
|
+
declare class PrivateStateExportError extends Error {
|
|
363
|
+
constructor(message: string);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Cause types for private state import errors.
|
|
367
|
+
*/
|
|
368
|
+
type PrivateStateImportErrorCause = 'decryption_failed' | 'invalid_format' | 'conflict' | 'unknown';
|
|
369
|
+
/**
|
|
370
|
+
* Base error thrown when importing private states fails.
|
|
371
|
+
*/
|
|
372
|
+
declare class PrivateStateImportError extends Error {
|
|
373
|
+
readonly cause?: PrivateStateImportErrorCause | undefined;
|
|
374
|
+
constructor(message: string, cause?: PrivateStateImportErrorCause | undefined);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Error thrown when decryption of export data fails.
|
|
378
|
+
* This could be due to wrong password, corrupted data, or tampered content.
|
|
379
|
+
* The specific cause is intentionally not disclosed to prevent oracle attacks.
|
|
380
|
+
*/
|
|
381
|
+
declare class ExportDecryptionError extends PrivateStateImportError {
|
|
382
|
+
constructor();
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Error thrown when the export data format is invalid.
|
|
386
|
+
*/
|
|
387
|
+
declare class InvalidExportFormatError extends PrivateStateImportError {
|
|
388
|
+
constructor(message?: string);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Error thrown when import conflicts with existing data and conflictStrategy is 'error'.
|
|
392
|
+
*/
|
|
393
|
+
declare class ImportConflictError extends PrivateStateImportError {
|
|
394
|
+
readonly conflictCount: number;
|
|
395
|
+
constructor(conflictCount: number);
|
|
396
|
+
}
|
|
359
397
|
|
|
360
398
|
/**
|
|
361
399
|
* A valid named log level.
|
|
@@ -403,6 +441,90 @@ interface MidnightProvider {
|
|
|
403
441
|
* A type representing an ID used to store a contract's private state.
|
|
404
442
|
*/
|
|
405
443
|
type PrivateStateId = string;
|
|
444
|
+
/**
|
|
445
|
+
* Represents the exported private state data structure.
|
|
446
|
+
* All metadata is included in the encrypted payload to prevent tampering.
|
|
447
|
+
*/
|
|
448
|
+
interface PrivateStateExport {
|
|
449
|
+
/**
|
|
450
|
+
* Format identifier. Must be 'midnight-private-state-export'.
|
|
451
|
+
*/
|
|
452
|
+
readonly format: 'midnight-private-state-export';
|
|
453
|
+
/**
|
|
454
|
+
* Encrypted payload containing version, metadata, and serialized private states.
|
|
455
|
+
* Format: base64-encoded AES-256-GCM encrypted JSON.
|
|
456
|
+
*/
|
|
457
|
+
readonly encryptedPayload: string;
|
|
458
|
+
/**
|
|
459
|
+
* Salt used for key derivation (hex-encoded, 32 bytes / 64 characters).
|
|
460
|
+
* Required for decryption with the export password.
|
|
461
|
+
*/
|
|
462
|
+
readonly salt: string;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Maximum number of states that can be exported/imported.
|
|
466
|
+
* This limit prevents memory exhaustion attacks.
|
|
467
|
+
*/
|
|
468
|
+
declare const MAX_EXPORT_STATES = 10000;
|
|
469
|
+
/**
|
|
470
|
+
* Options for exporting private states.
|
|
471
|
+
*/
|
|
472
|
+
interface ExportPrivateStatesOptions {
|
|
473
|
+
/**
|
|
474
|
+
* Password used to encrypt the export.
|
|
475
|
+
* Must be at least 16 characters.
|
|
476
|
+
* If not provided, uses the storage password.
|
|
477
|
+
*/
|
|
478
|
+
readonly password?: string;
|
|
479
|
+
/**
|
|
480
|
+
* Maximum number of states to export.
|
|
481
|
+
* Defaults to MAX_EXPORT_STATES (10000).
|
|
482
|
+
* Set to a lower value to limit memory usage.
|
|
483
|
+
*/
|
|
484
|
+
readonly maxStates?: number;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Options for importing private states.
|
|
488
|
+
*/
|
|
489
|
+
interface ImportPrivateStatesOptions {
|
|
490
|
+
/**
|
|
491
|
+
* Password used to decrypt the import.
|
|
492
|
+
* Must match the password used during export.
|
|
493
|
+
* If not provided, uses the storage password.
|
|
494
|
+
*/
|
|
495
|
+
readonly password?: string;
|
|
496
|
+
/**
|
|
497
|
+
* How to handle conflicts when a private state ID already exists.
|
|
498
|
+
* - 'skip': Keep existing state, ignore imported state
|
|
499
|
+
* - 'overwrite': Replace existing state with imported state
|
|
500
|
+
* - 'error': Throw an error if any conflict is detected
|
|
501
|
+
* Default: 'error'
|
|
502
|
+
*/
|
|
503
|
+
readonly conflictStrategy?: 'skip' | 'overwrite' | 'error';
|
|
504
|
+
/**
|
|
505
|
+
* Maximum number of states to import.
|
|
506
|
+
* Defaults to MAX_EXPORT_STATES (10000).
|
|
507
|
+
* Set to a lower value to limit memory usage.
|
|
508
|
+
*/
|
|
509
|
+
readonly maxStates?: number;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Result of an import operation.
|
|
513
|
+
*/
|
|
514
|
+
interface ImportPrivateStatesResult {
|
|
515
|
+
/**
|
|
516
|
+
* Number of states successfully imported.
|
|
517
|
+
*/
|
|
518
|
+
readonly imported: number;
|
|
519
|
+
/**
|
|
520
|
+
* Number of states skipped due to conflicts (when conflictStrategy is 'skip').
|
|
521
|
+
*/
|
|
522
|
+
readonly skipped: number;
|
|
523
|
+
/**
|
|
524
|
+
* Number of states that overwrote existing states (when conflictStrategy is 'overwrite').
|
|
525
|
+
*/
|
|
526
|
+
readonly overwritten: number;
|
|
527
|
+
}
|
|
406
528
|
/**
|
|
407
529
|
* Interface for a typed key-valued store containing contract private states.
|
|
408
530
|
*
|
|
@@ -410,6 +532,14 @@ type PrivateStateId = string;
|
|
|
410
532
|
* @typeParam PS - Parameter indicating the private state type stored, sometimes a union of private state types.
|
|
411
533
|
*/
|
|
412
534
|
interface PrivateStateProvider<PSI extends PrivateStateId = PrivateStateId, PS = any> {
|
|
535
|
+
/**
|
|
536
|
+
* Set the contract address for scoping private state operations.
|
|
537
|
+
* Must be called before any get/set/remove operations on private states.
|
|
538
|
+
* This provides namespace isolation between different contracts.
|
|
539
|
+
*
|
|
540
|
+
* @param address The contract address to scope operations to.
|
|
541
|
+
*/
|
|
542
|
+
setContractAddress(address: ContractAddress$2): void;
|
|
413
543
|
/**
|
|
414
544
|
* Store the given private state at the given private state ID.
|
|
415
545
|
*
|
|
@@ -456,6 +586,27 @@ interface PrivateStateProvider<PSI extends PrivateStateId = PrivateStateId, PS =
|
|
|
456
586
|
* Remove all contract signing keys.
|
|
457
587
|
*/
|
|
458
588
|
clearSigningKeys(): Promise<void>;
|
|
589
|
+
/**
|
|
590
|
+
* Export all private states as an encrypted JSON-serializable structure.
|
|
591
|
+
*
|
|
592
|
+
* NOTE: This does NOT export signing keys for security reasons.
|
|
593
|
+
*
|
|
594
|
+
* @param options Export options including optional custom password and state limit.
|
|
595
|
+
* @returns A JSON-serializable export structure that can be saved or transmitted.
|
|
596
|
+
* @throws {PrivateStateExportError} If no states exist to export or limit exceeded.
|
|
597
|
+
*/
|
|
598
|
+
exportPrivateStates(options?: ExportPrivateStatesOptions): Promise<PrivateStateExport>;
|
|
599
|
+
/**
|
|
600
|
+
* Import private states from a previously exported structure.
|
|
601
|
+
*
|
|
602
|
+
* @param exportData The export data structure to import.
|
|
603
|
+
* @param options Import options including password, conflict strategy, and state limit.
|
|
604
|
+
* @returns Result indicating how many states were imported/skipped/overwritten.
|
|
605
|
+
* @throws {ExportDecryptionError} If decryption fails (wrong password or corrupted data).
|
|
606
|
+
* @throws {InvalidExportFormatError} If the export format is invalid or unsupported.
|
|
607
|
+
* @throws {ImportConflictError} If conflictStrategy is 'error' and conflicts exist.
|
|
608
|
+
*/
|
|
609
|
+
importPrivateStates(exportData: PrivateStateExport, options?: ImportPrivateStatesOptions): Promise<ImportPrivateStatesResult>;
|
|
459
610
|
}
|
|
460
611
|
|
|
461
612
|
type UnboundTransaction = Transaction<SignatureEnabled, Proof, PreBinding>;
|
|
@@ -695,5 +846,5 @@ interface MidnightProviders<ICK extends Contract.ImpureCircuitId<Contract.Any> =
|
|
|
695
846
|
readonly loggerProvider?: LoggerProvider;
|
|
696
847
|
}
|
|
697
848
|
|
|
698
|
-
export { FailEntirely, FailFallible, InvalidProtocolSchemeError, LogLevel, SegmentFail, SegmentSuccess, SucceedEntirely, ZKConfigProvider, asContractAddress, asEffectOption, createProverKey, createVerifierKey, createZKIR, exitResultOrError, makeContractExecutableRuntime, zkConfigToProvingKeyMaterial };
|
|
699
|
-
export type { All, BlockHash, BlockHashConfig, BlockHeightConfig, ContractExecutableRuntimeOptions, ContractStateObservableConfig, Fees, FinalizedTxData, KeyMaterialProvider, Latest, LoggerProvider, MidnightProvider, MidnightProviders, PrivateStateId, PrivateStateProvider, ProofProvider, ProveTxConfig, ProverKey, PublicDataProvider, SegmentStatus, TxIdConfig, TxStatus, UnboundTransaction, UnshieldedBalance, UnshieldedBalances, UnshieldedUtxo, UnshieldedUtxos, VerifierKey, WalletProvider, ZKConfig, ZKIR };
|
|
849
|
+
export { ExportDecryptionError, FailEntirely, FailFallible, ImportConflictError, InvalidExportFormatError, InvalidProtocolSchemeError, LogLevel, MAX_EXPORT_STATES, PrivateStateExportError, PrivateStateImportError, SegmentFail, SegmentSuccess, SucceedEntirely, ZKConfigProvider, asContractAddress, asEffectOption, createProverKey, createVerifierKey, createZKIR, exitResultOrError, makeContractExecutableRuntime, zkConfigToProvingKeyMaterial };
|
|
850
|
+
export type { All, BlockHash, BlockHashConfig, BlockHeightConfig, ContractExecutableRuntimeOptions, ContractStateObservableConfig, ExportPrivateStatesOptions, Fees, FinalizedTxData, ImportPrivateStatesOptions, ImportPrivateStatesResult, KeyMaterialProvider, Latest, LoggerProvider, MidnightProvider, MidnightProviders, PrivateStateExport, PrivateStateId, PrivateStateImportErrorCause, PrivateStateProvider, ProofProvider, ProveTxConfig, ProverKey, PublicDataProvider, SegmentStatus, TxIdConfig, TxStatus, UnboundTransaction, UnshieldedBalance, UnshieldedBalances, UnshieldedUtxo, UnshieldedUtxos, VerifierKey, WalletProvider, ZKConfig, ZKIR };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ContractExecutable } from '@midnight-ntwrk/compact-js/effect';
|
|
2
2
|
import { ContractAddress as ContractAddress$1 } from '@midnight-ntwrk/platform-js';
|
|
3
|
-
import {
|
|
3
|
+
import { Option, Exit, ConfigError } from 'effect';
|
|
4
4
|
import { ManagedRuntime } from 'effect/ManagedRuntime';
|
|
5
|
-
import {
|
|
5
|
+
import { Transaction, SignatureEnabled, Proof, Binding, TransactionId, TransactionHash, ContractAddress, IntentHash, RawTokenType, FinalizedTransaction, UnprovenTransaction, PreBinding, ZswapChainState, CoinPublicKey, EncPublicKey } from '@midnight-ntwrk/ledger-v7';
|
|
6
6
|
export { Transaction } from '@midnight-ntwrk/ledger-v7';
|
|
7
7
|
import { LogFn } from 'pino';
|
|
8
8
|
import { ContractAddress as ContractAddress$2, SigningKey, ContractState } from '@midnight-ntwrk/compact-runtime';
|
|
@@ -356,6 +356,44 @@ declare class InvalidProtocolSchemeError extends Error {
|
|
|
356
356
|
*/
|
|
357
357
|
constructor(invalidScheme: string, allowableSchemes: string[]);
|
|
358
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* An error thrown when exporting private states fails.
|
|
361
|
+
*/
|
|
362
|
+
declare class PrivateStateExportError extends Error {
|
|
363
|
+
constructor(message: string);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Cause types for private state import errors.
|
|
367
|
+
*/
|
|
368
|
+
type PrivateStateImportErrorCause = 'decryption_failed' | 'invalid_format' | 'conflict' | 'unknown';
|
|
369
|
+
/**
|
|
370
|
+
* Base error thrown when importing private states fails.
|
|
371
|
+
*/
|
|
372
|
+
declare class PrivateStateImportError extends Error {
|
|
373
|
+
readonly cause?: PrivateStateImportErrorCause | undefined;
|
|
374
|
+
constructor(message: string, cause?: PrivateStateImportErrorCause | undefined);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Error thrown when decryption of export data fails.
|
|
378
|
+
* This could be due to wrong password, corrupted data, or tampered content.
|
|
379
|
+
* The specific cause is intentionally not disclosed to prevent oracle attacks.
|
|
380
|
+
*/
|
|
381
|
+
declare class ExportDecryptionError extends PrivateStateImportError {
|
|
382
|
+
constructor();
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Error thrown when the export data format is invalid.
|
|
386
|
+
*/
|
|
387
|
+
declare class InvalidExportFormatError extends PrivateStateImportError {
|
|
388
|
+
constructor(message?: string);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Error thrown when import conflicts with existing data and conflictStrategy is 'error'.
|
|
392
|
+
*/
|
|
393
|
+
declare class ImportConflictError extends PrivateStateImportError {
|
|
394
|
+
readonly conflictCount: number;
|
|
395
|
+
constructor(conflictCount: number);
|
|
396
|
+
}
|
|
359
397
|
|
|
360
398
|
/**
|
|
361
399
|
* A valid named log level.
|
|
@@ -403,6 +441,90 @@ interface MidnightProvider {
|
|
|
403
441
|
* A type representing an ID used to store a contract's private state.
|
|
404
442
|
*/
|
|
405
443
|
type PrivateStateId = string;
|
|
444
|
+
/**
|
|
445
|
+
* Represents the exported private state data structure.
|
|
446
|
+
* All metadata is included in the encrypted payload to prevent tampering.
|
|
447
|
+
*/
|
|
448
|
+
interface PrivateStateExport {
|
|
449
|
+
/**
|
|
450
|
+
* Format identifier. Must be 'midnight-private-state-export'.
|
|
451
|
+
*/
|
|
452
|
+
readonly format: 'midnight-private-state-export';
|
|
453
|
+
/**
|
|
454
|
+
* Encrypted payload containing version, metadata, and serialized private states.
|
|
455
|
+
* Format: base64-encoded AES-256-GCM encrypted JSON.
|
|
456
|
+
*/
|
|
457
|
+
readonly encryptedPayload: string;
|
|
458
|
+
/**
|
|
459
|
+
* Salt used for key derivation (hex-encoded, 32 bytes / 64 characters).
|
|
460
|
+
* Required for decryption with the export password.
|
|
461
|
+
*/
|
|
462
|
+
readonly salt: string;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Maximum number of states that can be exported/imported.
|
|
466
|
+
* This limit prevents memory exhaustion attacks.
|
|
467
|
+
*/
|
|
468
|
+
declare const MAX_EXPORT_STATES = 10000;
|
|
469
|
+
/**
|
|
470
|
+
* Options for exporting private states.
|
|
471
|
+
*/
|
|
472
|
+
interface ExportPrivateStatesOptions {
|
|
473
|
+
/**
|
|
474
|
+
* Password used to encrypt the export.
|
|
475
|
+
* Must be at least 16 characters.
|
|
476
|
+
* If not provided, uses the storage password.
|
|
477
|
+
*/
|
|
478
|
+
readonly password?: string;
|
|
479
|
+
/**
|
|
480
|
+
* Maximum number of states to export.
|
|
481
|
+
* Defaults to MAX_EXPORT_STATES (10000).
|
|
482
|
+
* Set to a lower value to limit memory usage.
|
|
483
|
+
*/
|
|
484
|
+
readonly maxStates?: number;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Options for importing private states.
|
|
488
|
+
*/
|
|
489
|
+
interface ImportPrivateStatesOptions {
|
|
490
|
+
/**
|
|
491
|
+
* Password used to decrypt the import.
|
|
492
|
+
* Must match the password used during export.
|
|
493
|
+
* If not provided, uses the storage password.
|
|
494
|
+
*/
|
|
495
|
+
readonly password?: string;
|
|
496
|
+
/**
|
|
497
|
+
* How to handle conflicts when a private state ID already exists.
|
|
498
|
+
* - 'skip': Keep existing state, ignore imported state
|
|
499
|
+
* - 'overwrite': Replace existing state with imported state
|
|
500
|
+
* - 'error': Throw an error if any conflict is detected
|
|
501
|
+
* Default: 'error'
|
|
502
|
+
*/
|
|
503
|
+
readonly conflictStrategy?: 'skip' | 'overwrite' | 'error';
|
|
504
|
+
/**
|
|
505
|
+
* Maximum number of states to import.
|
|
506
|
+
* Defaults to MAX_EXPORT_STATES (10000).
|
|
507
|
+
* Set to a lower value to limit memory usage.
|
|
508
|
+
*/
|
|
509
|
+
readonly maxStates?: number;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Result of an import operation.
|
|
513
|
+
*/
|
|
514
|
+
interface ImportPrivateStatesResult {
|
|
515
|
+
/**
|
|
516
|
+
* Number of states successfully imported.
|
|
517
|
+
*/
|
|
518
|
+
readonly imported: number;
|
|
519
|
+
/**
|
|
520
|
+
* Number of states skipped due to conflicts (when conflictStrategy is 'skip').
|
|
521
|
+
*/
|
|
522
|
+
readonly skipped: number;
|
|
523
|
+
/**
|
|
524
|
+
* Number of states that overwrote existing states (when conflictStrategy is 'overwrite').
|
|
525
|
+
*/
|
|
526
|
+
readonly overwritten: number;
|
|
527
|
+
}
|
|
406
528
|
/**
|
|
407
529
|
* Interface for a typed key-valued store containing contract private states.
|
|
408
530
|
*
|
|
@@ -410,6 +532,14 @@ type PrivateStateId = string;
|
|
|
410
532
|
* @typeParam PS - Parameter indicating the private state type stored, sometimes a union of private state types.
|
|
411
533
|
*/
|
|
412
534
|
interface PrivateStateProvider<PSI extends PrivateStateId = PrivateStateId, PS = any> {
|
|
535
|
+
/**
|
|
536
|
+
* Set the contract address for scoping private state operations.
|
|
537
|
+
* Must be called before any get/set/remove operations on private states.
|
|
538
|
+
* This provides namespace isolation between different contracts.
|
|
539
|
+
*
|
|
540
|
+
* @param address The contract address to scope operations to.
|
|
541
|
+
*/
|
|
542
|
+
setContractAddress(address: ContractAddress$2): void;
|
|
413
543
|
/**
|
|
414
544
|
* Store the given private state at the given private state ID.
|
|
415
545
|
*
|
|
@@ -456,6 +586,27 @@ interface PrivateStateProvider<PSI extends PrivateStateId = PrivateStateId, PS =
|
|
|
456
586
|
* Remove all contract signing keys.
|
|
457
587
|
*/
|
|
458
588
|
clearSigningKeys(): Promise<void>;
|
|
589
|
+
/**
|
|
590
|
+
* Export all private states as an encrypted JSON-serializable structure.
|
|
591
|
+
*
|
|
592
|
+
* NOTE: This does NOT export signing keys for security reasons.
|
|
593
|
+
*
|
|
594
|
+
* @param options Export options including optional custom password and state limit.
|
|
595
|
+
* @returns A JSON-serializable export structure that can be saved or transmitted.
|
|
596
|
+
* @throws {PrivateStateExportError} If no states exist to export or limit exceeded.
|
|
597
|
+
*/
|
|
598
|
+
exportPrivateStates(options?: ExportPrivateStatesOptions): Promise<PrivateStateExport>;
|
|
599
|
+
/**
|
|
600
|
+
* Import private states from a previously exported structure.
|
|
601
|
+
*
|
|
602
|
+
* @param exportData The export data structure to import.
|
|
603
|
+
* @param options Import options including password, conflict strategy, and state limit.
|
|
604
|
+
* @returns Result indicating how many states were imported/skipped/overwritten.
|
|
605
|
+
* @throws {ExportDecryptionError} If decryption fails (wrong password or corrupted data).
|
|
606
|
+
* @throws {InvalidExportFormatError} If the export format is invalid or unsupported.
|
|
607
|
+
* @throws {ImportConflictError} If conflictStrategy is 'error' and conflicts exist.
|
|
608
|
+
*/
|
|
609
|
+
importPrivateStates(exportData: PrivateStateExport, options?: ImportPrivateStatesOptions): Promise<ImportPrivateStatesResult>;
|
|
459
610
|
}
|
|
460
611
|
|
|
461
612
|
type UnboundTransaction = Transaction<SignatureEnabled, Proof, PreBinding>;
|
|
@@ -695,5 +846,5 @@ interface MidnightProviders<ICK extends Contract.ImpureCircuitId<Contract.Any> =
|
|
|
695
846
|
readonly loggerProvider?: LoggerProvider;
|
|
696
847
|
}
|
|
697
848
|
|
|
698
|
-
export { FailEntirely, FailFallible, InvalidProtocolSchemeError, LogLevel, SegmentFail, SegmentSuccess, SucceedEntirely, ZKConfigProvider, asContractAddress, asEffectOption, createProverKey, createVerifierKey, createZKIR, exitResultOrError, makeContractExecutableRuntime, zkConfigToProvingKeyMaterial };
|
|
699
|
-
export type { All, BlockHash, BlockHashConfig, BlockHeightConfig, ContractExecutableRuntimeOptions, ContractStateObservableConfig, Fees, FinalizedTxData, KeyMaterialProvider, Latest, LoggerProvider, MidnightProvider, MidnightProviders, PrivateStateId, PrivateStateProvider, ProofProvider, ProveTxConfig, ProverKey, PublicDataProvider, SegmentStatus, TxIdConfig, TxStatus, UnboundTransaction, UnshieldedBalance, UnshieldedBalances, UnshieldedUtxo, UnshieldedUtxos, VerifierKey, WalletProvider, ZKConfig, ZKIR };
|
|
849
|
+
export { ExportDecryptionError, FailEntirely, FailFallible, ImportConflictError, InvalidExportFormatError, InvalidProtocolSchemeError, LogLevel, MAX_EXPORT_STATES, PrivateStateExportError, PrivateStateImportError, SegmentFail, SegmentSuccess, SucceedEntirely, ZKConfigProvider, asContractAddress, asEffectOption, createProverKey, createVerifierKey, createZKIR, exitResultOrError, makeContractExecutableRuntime, zkConfigToProvingKeyMaterial };
|
|
850
|
+
export type { All, BlockHash, BlockHashConfig, BlockHeightConfig, ContractExecutableRuntimeOptions, ContractStateObservableConfig, ExportPrivateStatesOptions, Fees, FinalizedTxData, ImportPrivateStatesOptions, ImportPrivateStatesResult, KeyMaterialProvider, Latest, LoggerProvider, MidnightProvider, MidnightProviders, PrivateStateExport, PrivateStateId, PrivateStateImportErrorCause, PrivateStateProvider, ProofProvider, ProveTxConfig, ProverKey, PublicDataProvider, SegmentStatus, TxIdConfig, TxStatus, UnboundTransaction, UnshieldedBalance, UnshieldedBalances, UnshieldedUtxo, UnshieldedUtxos, VerifierKey, WalletProvider, ZKConfig, ZKIR };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ContractExecutableRuntime, ZKConfiguration, ZKConfigurationReadError, Contract } from '@midnight-ntwrk/compact-js/effect';
|
|
2
2
|
import { ContractAddress } from '@midnight-ntwrk/platform-js';
|
|
3
3
|
import * as Configuration from '@midnight-ntwrk/platform-js/effect/Configuration';
|
|
4
|
-
import { Exit,
|
|
4
|
+
import { Exit, Cause, Option, Layer, ConfigProvider, Effect } from 'effect';
|
|
5
5
|
export { Transaction } from '@midnight-ntwrk/ledger-v7';
|
|
6
6
|
|
|
7
7
|
/*
|
|
@@ -118,6 +118,57 @@ class InvalidProtocolSchemeError extends Error {
|
|
|
118
118
|
this.allowableSchemes = allowableSchemes;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* An error thrown when exporting private states fails.
|
|
123
|
+
*/
|
|
124
|
+
class PrivateStateExportError extends Error {
|
|
125
|
+
constructor(message) {
|
|
126
|
+
super(message);
|
|
127
|
+
this.name = 'PrivateStateExportError';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Base error thrown when importing private states fails.
|
|
132
|
+
*/
|
|
133
|
+
class PrivateStateImportError extends Error {
|
|
134
|
+
cause;
|
|
135
|
+
constructor(message, cause) {
|
|
136
|
+
super(message);
|
|
137
|
+
this.cause = cause;
|
|
138
|
+
this.name = 'PrivateStateImportError';
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Error thrown when decryption of export data fails.
|
|
143
|
+
* This could be due to wrong password, corrupted data, or tampered content.
|
|
144
|
+
* The specific cause is intentionally not disclosed to prevent oracle attacks.
|
|
145
|
+
*/
|
|
146
|
+
class ExportDecryptionError extends PrivateStateImportError {
|
|
147
|
+
constructor() {
|
|
148
|
+
super('Failed to decrypt export data. The password may be incorrect or the data may be corrupted.', 'decryption_failed');
|
|
149
|
+
this.name = 'ExportDecryptionError';
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Error thrown when the export data format is invalid.
|
|
154
|
+
*/
|
|
155
|
+
class InvalidExportFormatError extends PrivateStateImportError {
|
|
156
|
+
constructor(message = 'Invalid export format') {
|
|
157
|
+
super(message, 'invalid_format');
|
|
158
|
+
this.name = 'InvalidExportFormatError';
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Error thrown when import conflicts with existing data and conflictStrategy is 'error'.
|
|
163
|
+
*/
|
|
164
|
+
class ImportConflictError extends PrivateStateImportError {
|
|
165
|
+
conflictCount;
|
|
166
|
+
constructor(conflictCount) {
|
|
167
|
+
super(`Import conflicts with ${conflictCount} existing private state${conflictCount === 1 ? '' : 's'}`, 'conflict');
|
|
168
|
+
this.conflictCount = conflictCount;
|
|
169
|
+
this.name = 'ImportConflictError';
|
|
170
|
+
}
|
|
171
|
+
}
|
|
121
172
|
|
|
122
173
|
/*
|
|
123
174
|
* This file is part of midnight-js.
|
|
@@ -227,6 +278,26 @@ const FailFallible = 'FailFallible';
|
|
|
227
278
|
*/
|
|
228
279
|
const SucceedEntirely = 'SucceedEntirely';
|
|
229
280
|
|
|
281
|
+
/*
|
|
282
|
+
* This file is part of midnight-js.
|
|
283
|
+
* Copyright (C) 2025 Midnight Foundation
|
|
284
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
285
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
286
|
+
* You may not use this file except in compliance with the License.
|
|
287
|
+
* You may obtain a copy of the License at
|
|
288
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
289
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
290
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
291
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
292
|
+
* See the License for the specific language governing permissions and
|
|
293
|
+
* limitations under the License.
|
|
294
|
+
*/
|
|
295
|
+
/**
|
|
296
|
+
* Maximum number of states that can be exported/imported.
|
|
297
|
+
* This limit prevents memory exhaustion attacks.
|
|
298
|
+
*/
|
|
299
|
+
const MAX_EXPORT_STATES = 10000;
|
|
300
|
+
|
|
230
301
|
/*
|
|
231
302
|
* This file is part of midnight-js.
|
|
232
303
|
* Copyright (C) 2025 Midnight Foundation
|
|
@@ -276,5 +347,5 @@ class ZKConfigProvider {
|
|
|
276
347
|
}
|
|
277
348
|
}
|
|
278
349
|
|
|
279
|
-
export { FailEntirely, FailFallible, InvalidProtocolSchemeError, LogLevel, SegmentFail, SegmentSuccess, SucceedEntirely, ZKConfigProvider, asContractAddress, asEffectOption, createProverKey, createVerifierKey, createZKIR, exitResultOrError, makeContractExecutableRuntime, zkConfigToProvingKeyMaterial };
|
|
350
|
+
export { ExportDecryptionError, FailEntirely, FailFallible, ImportConflictError, InvalidExportFormatError, InvalidProtocolSchemeError, LogLevel, MAX_EXPORT_STATES, PrivateStateExportError, PrivateStateImportError, SegmentFail, SegmentSuccess, SucceedEntirely, ZKConfigProvider, asContractAddress, asEffectOption, createProverKey, createVerifierKey, createZKIR, exitResultOrError, makeContractExecutableRuntime, zkConfigToProvingKeyMaterial };
|
|
280
351
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/contract.ts","../src/errors.ts","../src/logger-provider.ts","../src/midnight-types.ts","../src/zk-config-provider.ts"],"sourcesContent":[null,null,null,null,null],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;AAaG;AAWH;;;;;;;;AAQG;AACH,MAAM,iBAAiB,GAAG,CAAsC,gBAA0C,KACxG,CAAC,gBA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AAK,CAAC,CAAA,0BAAA,EAA6B,aAAa,CAAA,iCAAA,EAAoC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,CAAE,CAAC;QAHjG,IAAA,CAAA,aAAa,GAAb,aAAa;QACb,IAAA,CAAA,gBAAgB,GAAhB,gBAAgB;IAGlC;AACD;;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/contract.ts","../src/errors.ts","../src/logger-provider.ts","../src/midnight-types.ts","../src/private-state-provider.ts","../src/zk-config-provider.ts"],"sourcesContent":[null,null,null,null,null,null],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;AAaG;AAWH;;;;;;;;AAQG;AACH,MAAM,iBAAiB,GAAG,CAAsC,gBAA0C,KACxG,CAAC,gBAA0D,KACzD,MAAM,CAAC,GAAG,CAAC,aAAS;;;IAGlB,MAAM,cAAc,GAAG,CAAC,eAA4C,KAClE,MAAM,CAAC,UAAU,CAAC;AAChB,QAAA,GAAG,EAAE,MAAM,gBAAgB,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC;AACjI,QAAA,KAAK,EAAE,CAAC,GAAY,KAAK,wBAAwB,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,eAAe,EAAE,cAAc,EAAE,GAAG;AAClH,KAAA,CAAC;IACJ,OAAO;QACL,cAAc;QACd,eAAe,EAAE,CAAC,gBAAgB,KAChC,MAAM,CAAC,OAAO,CACZ,gBAAgB,EAChB,CAAC,eAAe,KACd,cAAc,CAAC,eAAe,CAAC,CAAC,IAAI,CAClC,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,KAAK,CAAC,eAAe,EAAE,WAAW,CAAU,CAAC,CACrE,EACH,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE;KAEO;AAC3D,CAAC,CAA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D;;;;"}
|
|
@@ -3,6 +3,90 @@ import type { ContractAddress, SigningKey } from '@midnight-ntwrk/compact-runtim
|
|
|
3
3
|
* A type representing an ID used to store a contract's private state.
|
|
4
4
|
*/
|
|
5
5
|
export type PrivateStateId = string;
|
|
6
|
+
/**
|
|
7
|
+
* Represents the exported private state data structure.
|
|
8
|
+
* All metadata is included in the encrypted payload to prevent tampering.
|
|
9
|
+
*/
|
|
10
|
+
export interface PrivateStateExport {
|
|
11
|
+
/**
|
|
12
|
+
* Format identifier. Must be 'midnight-private-state-export'.
|
|
13
|
+
*/
|
|
14
|
+
readonly format: 'midnight-private-state-export';
|
|
15
|
+
/**
|
|
16
|
+
* Encrypted payload containing version, metadata, and serialized private states.
|
|
17
|
+
* Format: base64-encoded AES-256-GCM encrypted JSON.
|
|
18
|
+
*/
|
|
19
|
+
readonly encryptedPayload: string;
|
|
20
|
+
/**
|
|
21
|
+
* Salt used for key derivation (hex-encoded, 32 bytes / 64 characters).
|
|
22
|
+
* Required for decryption with the export password.
|
|
23
|
+
*/
|
|
24
|
+
readonly salt: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Maximum number of states that can be exported/imported.
|
|
28
|
+
* This limit prevents memory exhaustion attacks.
|
|
29
|
+
*/
|
|
30
|
+
export declare const MAX_EXPORT_STATES = 10000;
|
|
31
|
+
/**
|
|
32
|
+
* Options for exporting private states.
|
|
33
|
+
*/
|
|
34
|
+
export interface ExportPrivateStatesOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Password used to encrypt the export.
|
|
37
|
+
* Must be at least 16 characters.
|
|
38
|
+
* If not provided, uses the storage password.
|
|
39
|
+
*/
|
|
40
|
+
readonly password?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Maximum number of states to export.
|
|
43
|
+
* Defaults to MAX_EXPORT_STATES (10000).
|
|
44
|
+
* Set to a lower value to limit memory usage.
|
|
45
|
+
*/
|
|
46
|
+
readonly maxStates?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Options for importing private states.
|
|
50
|
+
*/
|
|
51
|
+
export interface ImportPrivateStatesOptions {
|
|
52
|
+
/**
|
|
53
|
+
* Password used to decrypt the import.
|
|
54
|
+
* Must match the password used during export.
|
|
55
|
+
* If not provided, uses the storage password.
|
|
56
|
+
*/
|
|
57
|
+
readonly password?: string;
|
|
58
|
+
/**
|
|
59
|
+
* How to handle conflicts when a private state ID already exists.
|
|
60
|
+
* - 'skip': Keep existing state, ignore imported state
|
|
61
|
+
* - 'overwrite': Replace existing state with imported state
|
|
62
|
+
* - 'error': Throw an error if any conflict is detected
|
|
63
|
+
* Default: 'error'
|
|
64
|
+
*/
|
|
65
|
+
readonly conflictStrategy?: 'skip' | 'overwrite' | 'error';
|
|
66
|
+
/**
|
|
67
|
+
* Maximum number of states to import.
|
|
68
|
+
* Defaults to MAX_EXPORT_STATES (10000).
|
|
69
|
+
* Set to a lower value to limit memory usage.
|
|
70
|
+
*/
|
|
71
|
+
readonly maxStates?: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Result of an import operation.
|
|
75
|
+
*/
|
|
76
|
+
export interface ImportPrivateStatesResult {
|
|
77
|
+
/**
|
|
78
|
+
* Number of states successfully imported.
|
|
79
|
+
*/
|
|
80
|
+
readonly imported: number;
|
|
81
|
+
/**
|
|
82
|
+
* Number of states skipped due to conflicts (when conflictStrategy is 'skip').
|
|
83
|
+
*/
|
|
84
|
+
readonly skipped: number;
|
|
85
|
+
/**
|
|
86
|
+
* Number of states that overwrote existing states (when conflictStrategy is 'overwrite').
|
|
87
|
+
*/
|
|
88
|
+
readonly overwritten: number;
|
|
89
|
+
}
|
|
6
90
|
/**
|
|
7
91
|
* Interface for a typed key-valued store containing contract private states.
|
|
8
92
|
*
|
|
@@ -10,6 +94,14 @@ export type PrivateStateId = string;
|
|
|
10
94
|
* @typeParam PS - Parameter indicating the private state type stored, sometimes a union of private state types.
|
|
11
95
|
*/
|
|
12
96
|
export interface PrivateStateProvider<PSI extends PrivateStateId = PrivateStateId, PS = any> {
|
|
97
|
+
/**
|
|
98
|
+
* Set the contract address for scoping private state operations.
|
|
99
|
+
* Must be called before any get/set/remove operations on private states.
|
|
100
|
+
* This provides namespace isolation between different contracts.
|
|
101
|
+
*
|
|
102
|
+
* @param address The contract address to scope operations to.
|
|
103
|
+
*/
|
|
104
|
+
setContractAddress(address: ContractAddress): void;
|
|
13
105
|
/**
|
|
14
106
|
* Store the given private state at the given private state ID.
|
|
15
107
|
*
|
|
@@ -56,5 +148,26 @@ export interface PrivateStateProvider<PSI extends PrivateStateId = PrivateStateI
|
|
|
56
148
|
* Remove all contract signing keys.
|
|
57
149
|
*/
|
|
58
150
|
clearSigningKeys(): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Export all private states as an encrypted JSON-serializable structure.
|
|
153
|
+
*
|
|
154
|
+
* NOTE: This does NOT export signing keys for security reasons.
|
|
155
|
+
*
|
|
156
|
+
* @param options Export options including optional custom password and state limit.
|
|
157
|
+
* @returns A JSON-serializable export structure that can be saved or transmitted.
|
|
158
|
+
* @throws {PrivateStateExportError} If no states exist to export or limit exceeded.
|
|
159
|
+
*/
|
|
160
|
+
exportPrivateStates(options?: ExportPrivateStatesOptions): Promise<PrivateStateExport>;
|
|
161
|
+
/**
|
|
162
|
+
* Import private states from a previously exported structure.
|
|
163
|
+
*
|
|
164
|
+
* @param exportData The export data structure to import.
|
|
165
|
+
* @param options Import options including password, conflict strategy, and state limit.
|
|
166
|
+
* @returns Result indicating how many states were imported/skipped/overwritten.
|
|
167
|
+
* @throws {ExportDecryptionError} If decryption fails (wrong password or corrupted data).
|
|
168
|
+
* @throws {InvalidExportFormatError} If the export format is invalid or unsupported.
|
|
169
|
+
* @throws {ImportConflictError} If conflictStrategy is 'error' and conflicts exist.
|
|
170
|
+
*/
|
|
171
|
+
importPrivateStates(exportData: PrivateStateExport, options?: ImportPrivateStatesOptions): Promise<ImportPrivateStatesResult>;
|
|
59
172
|
}
|
|
60
173
|
//# sourceMappingURL=private-state-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-state-provider.d.ts","sourceRoot":"","sources":["../src/private-state-provider.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,eAAe,EAAC,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"private-state-provider.d.ts","sourceRoot":"","sources":["../src/private-state-provider.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,eAAe,EAAC,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,+BAA+B,CAAC;IAEjD;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAElC;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;;OAMG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC;IAE3D;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;I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AAE,kBAAkB,EAC9B,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,yBAAyB,CAAC,CAAC;CACvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midnight-ntwrk/midnight-js-types",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Shared data types and interfaces for MidnightJS modules",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,6 +32,5 @@
|
|
|
32
32
|
"@midnight-ntwrk/compact-js": "2.4.0",
|
|
33
33
|
"@midnight-ntwrk/platform-js": "2.2.0",
|
|
34
34
|
"rxjs": "^7.5.0"
|
|
35
|
-
}
|
|
36
|
-
"stableVersion": "3.0.0"
|
|
35
|
+
}
|
|
37
36
|
}
|