@dstorage-tech/dstorage-sdk 0.0.4 → 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 +2 -0
- package/dist/browser.mjs +9 -8
- package/dist/index.js +8 -3
- package/dist/index.mjs +8 -3
- package/package.json +2 -1
- package/dist/KeypairEncryptionAdapter-AE75YC4W-AOWNSH2M.mjs +0 -9
- package/dist/KeypairEncryptionAdapter-AE75YC4W-BAVHRNNJ.mjs +0 -1
- package/dist/KeypairEncryptionAdapter-AE75YC4W-BEYO4RUO.mjs +0 -1
- package/dist/KeypairEncryptionAdapter-AE75YC4W-VAOH6AAL.mjs +0 -9
- package/dist/KeypairEncryptionAdapter-XUKCLRFU-6ERIZN2M.mjs +0 -1
- package/dist/MnemonicEncryptionAdapter-J6IE5OKA-6DFVUVD6.mjs +0 -1
- package/dist/MnemonicEncryptionAdapter-J6IE5OKA-O5AJPX42.mjs +0 -1
- package/dist/MnemonicEncryptionAdapter-J6IE5OKA-SI6TBLTQ.mjs +0 -9
- package/dist/MnemonicEncryptionAdapter-J6IE5OKA-WEPFOTSJ.mjs +0 -9
- package/dist/MnemonicEncryptionAdapter-RCHUETBP-ELAMJMMO.mjs +0 -1
- package/dist/PasswordEncryptionAdapter-CWOXUGR4-2YZ64B4A.mjs +0 -1
- package/dist/PasswordEncryptionAdapter-CWOXUGR4-DCEGC2NX.mjs +0 -1
- package/dist/PasswordEncryptionAdapter-CWOXUGR4-QEGGYPFJ.mjs +0 -13
- package/dist/PasswordEncryptionAdapter-CWOXUGR4-ZYUBUYUI.mjs +0 -13
- package/dist/PasswordEncryptionAdapter-ECHND672-XVBPHPPT.mjs +0 -1
- package/dist/chunk-4YMF57VY.mjs +0 -1
- package/dist/chunk-5MZ7FPPY.mjs +0 -1
- package/dist/chunk-5P4EW2YL.mjs +0 -1
- package/dist/chunk-5RW7SGA7.mjs +0 -1
- package/dist/chunk-62RSKZ6T.mjs +0 -118
- package/dist/chunk-BBJCQFWP.mjs +0 -275
- package/dist/chunk-EYF3263P.mjs +0 -2049
- package/dist/chunk-GUYENY5N.mjs +0 -1
- package/dist/chunk-L5QD6GHB.mjs +0 -101
- package/dist/chunk-PKHRAYFD.mjs +0 -1
- package/dist/chunk-PLAOCKSS.mjs +0 -101
- package/dist/chunk-QKA2DCR6.mjs +0 -118
- package/dist/chunk-RPSRFFXN.mjs +0 -275
- package/dist/chunk-TESUOXRJ.mjs +0 -1
- package/dist/chunk-TMLXCRJU.mjs +0 -1
- package/dist/chunk-TNRKN4LB.mjs +0 -1
- package/dist/chunk-TSZ37JDY.mjs +0 -2596
- package/dist/chunk-U3MS6KMF.mjs +0 -1
- package/dist/chunk-UBALMYIY.mjs +0 -2049
- package/dist/chunk-UOOF4V2Y.mjs +0 -1
- package/dist/chunk-Z2TH6U4C.mjs +0 -3
- package/dist/chunk-ZEPZ4QDD.mjs +0 -1
- package/dist/chunk-ZGUY5EIR.mjs +0 -1
- package/dist/contract-api-AO4RGPLT-4HRCMSCE.mjs +0 -279
- package/dist/contract-api-AO4RGPLT-ADH6ZDKC.mjs +0 -279
- package/dist/contract-api-AO4RGPLT-PAMIPEI3.mjs +0 -1
- package/dist/contract-api-AO4RGPLT-W3RSVP5A.mjs +0 -1
- package/dist/contract-api-AO4RGPLT-WENYDV6I.mjs +0 -1
- package/dist/contract-api-TJ7JPHZA-ZWP3EH7D.mjs +0 -279
- package/dist/dataregistry-simulator-E6RTGGWT-QGCYR3VF.mjs +0 -1
- package/dist/dist-655VYUPJ.mjs +0 -1
- package/dist/dist-MEZZWKP4.mjs +0 -1
- package/dist/dist-UD4WRMYJ.mjs +0 -65
- package/dist/esm5-AGBDHMNS.mjs +0 -1
- package/dist/in-memory-private-state-NGOP37V7-XFJFNFCQ.mjs +0 -1
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChainErrorCode
|
|
3
|
-
} from "./chunk-4X5K43JF.mjs";
|
|
4
|
-
import {
|
|
5
|
-
DStorageError
|
|
6
|
-
} from "./chunk-BWLEAAFW.mjs";
|
|
7
|
-
import {
|
|
8
|
-
CompiledDataRegistryContract,
|
|
9
|
-
createDataRegistryPrivateState,
|
|
10
|
-
ledger
|
|
11
|
-
} from "./chunk-VDZ7F7MP.mjs";
|
|
12
|
-
import "./chunk-5QOKJEH3.mjs";
|
|
13
|
-
import {
|
|
14
|
-
require_cjs
|
|
15
|
-
} from "./chunk-25I6ZXUC.mjs";
|
|
16
|
-
import {
|
|
17
|
-
__toESM
|
|
18
|
-
} from "./chunk-UJCSKKID.mjs";
|
|
19
|
-
|
|
20
|
-
// ../chain/dist/contract-api-AO4RGPLT.mjs
|
|
21
|
-
var import_rxjs = __toESM(require_cjs(), 1);
|
|
22
|
-
import {
|
|
23
|
-
deployContract,
|
|
24
|
-
findDeployedContract,
|
|
25
|
-
withContractScopedTransaction
|
|
26
|
-
} from "@midnight-ntwrk/midnight-js-contracts";
|
|
27
|
-
import { toHex } from "@midnight-ntwrk/midnight-js-utils";
|
|
28
|
-
var dataRegistryPrivateStateKey = "DataRegistryPrivateState";
|
|
29
|
-
var SUPPORTED_CONTRACT_VERSION = 0n;
|
|
30
|
-
function validateContractVersion(version, contractAddress) {
|
|
31
|
-
if (version !== SUPPORTED_CONTRACT_VERSION) {
|
|
32
|
-
throw new DStorageError(
|
|
33
|
-
ChainErrorCode.CONTRACT_UNSUPPORTED_VERSION,
|
|
34
|
-
`[dStorage/midnight] Unsupported contract version ${version} at ${contractAddress}. This SDK supports version ${SUPPORTED_CONTRACT_VERSION} only. Deploy a compatible DataRegistry contract or upgrade the SDK.`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
var DataRegistryAPI = class _DataRegistryAPI {
|
|
39
|
-
/** @internal */
|
|
40
|
-
constructor(deployedContract, providers, logger) {
|
|
41
|
-
this.deployedContract = deployedContract;
|
|
42
|
-
this.providers = providers;
|
|
43
|
-
this.logger = logger;
|
|
44
|
-
this.deployedContractAddress = deployedContract.deployTxData.public.contractAddress;
|
|
45
|
-
this.state$ = (0, import_rxjs.combineLatest)(
|
|
46
|
-
[
|
|
47
|
-
// Combine public (ledger) state with...
|
|
48
|
-
providers.publicDataProvider.contractStateObservable(this.deployedContractAddress, {
|
|
49
|
-
type: "latest"
|
|
50
|
-
}).pipe(
|
|
51
|
-
(0, import_rxjs.map)((contractState) => ledger(contractState.data)),
|
|
52
|
-
(0, import_rxjs.tap)(
|
|
53
|
-
(ledgerState) => logger?.debug?.(
|
|
54
|
-
"dStorage/midnight",
|
|
55
|
-
`ledger state changed: refCounter=${ledgerState.refCounter}`
|
|
56
|
-
)
|
|
57
|
-
)
|
|
58
|
-
),
|
|
59
|
-
// ...private state...
|
|
60
|
-
// since the private state of the DataRegistry application never changes, we can query the
|
|
61
|
-
// private state once and always use the same value with `combineLatest`. In applications
|
|
62
|
-
// where the private state is expected to change, we would need to make this an `Observable`.
|
|
63
|
-
(0, import_rxjs.from)(
|
|
64
|
-
providers.privateStateProvider.get(
|
|
65
|
-
dataRegistryPrivateStateKey
|
|
66
|
-
)
|
|
67
|
-
)
|
|
68
|
-
],
|
|
69
|
-
// ...and combine them to produce the required derived state.
|
|
70
|
-
// isOurs is set to false here — ownership is determined by the core SDK
|
|
71
|
-
// (dStorage.ts) by attempting to unwrap the DEK from the keyEnvelope using
|
|
72
|
-
// the available KEKs. This avoids coupling the chain layer to key material.
|
|
73
|
-
(ledgerState, _privateState) => {
|
|
74
|
-
const references = /* @__PURE__ */ new Map();
|
|
75
|
-
for (const [id, refEntry] of ledgerState.references) {
|
|
76
|
-
const refId = toHex(id);
|
|
77
|
-
references.set(refId, refEntry);
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
references,
|
|
81
|
-
refCounter: ledgerState.refCounter,
|
|
82
|
-
contractVersion: ledgerState.contractVersion
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
).pipe(
|
|
86
|
-
// Keep one live subscription to the indexer WebSocket for the lifetime of
|
|
87
|
-
// this API instance. Without shareReplay, each firstValueFrom(state$) call
|
|
88
|
-
// creates a new subscription — the indexer does not replay the last emitted
|
|
89
|
-
// state to new subscribers, so callers would receive stale data until the
|
|
90
|
-
// next on-chain change arrives. shareReplay(1) ensures:
|
|
91
|
-
// 1. The indexer connection is established once and kept alive.
|
|
92
|
-
// 2. Every new subscriber (e.g. listReferences, readReference) immediately
|
|
93
|
-
// receives the most recently emitted state.
|
|
94
|
-
// 3. Future indexer pushes (after upload/remove txs) still update the cache.
|
|
95
|
-
(0, import_rxjs.shareReplay)({ bufferSize: 1, refCount: false })
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
async storeReference(storageId, encryptionScheme, storageProvider, metadata, writtenAt, keyEnvelope, contentHash, ownerSecret) {
|
|
99
|
-
this.logger?.log(
|
|
100
|
-
"dStorage/midnight",
|
|
101
|
-
`storing reference: storageId=${storageId}`
|
|
102
|
-
);
|
|
103
|
-
await this.providers.privateStateProvider.set(dataRegistryPrivateStateKey, {
|
|
104
|
-
ownerSecret: new Uint8Array(ownerSecret)
|
|
105
|
-
});
|
|
106
|
-
try {
|
|
107
|
-
const txData = await withContractScopedTransaction(
|
|
108
|
-
this.providers,
|
|
109
|
-
async (txCtx) => {
|
|
110
|
-
await this.deployedContract.callTx.storeReference(
|
|
111
|
-
txCtx,
|
|
112
|
-
storageId,
|
|
113
|
-
encryptionScheme,
|
|
114
|
-
storageProvider,
|
|
115
|
-
metadata,
|
|
116
|
-
writtenAt,
|
|
117
|
-
keyEnvelope,
|
|
118
|
-
contentHash
|
|
119
|
-
);
|
|
120
|
-
},
|
|
121
|
-
{ scopeName: "storeReference" }
|
|
122
|
-
);
|
|
123
|
-
const txHash = txData.public.txHash ?? txData.public.txId ?? "";
|
|
124
|
-
const blockHeight = Number(txData.public.blockHeight ?? 0);
|
|
125
|
-
const circuitResult = txData.private.result;
|
|
126
|
-
if (!(circuitResult instanceof Uint8Array)) {
|
|
127
|
-
throw new DStorageError(
|
|
128
|
-
ChainErrorCode.CONTRACT_CIRCUIT_RESULT_MISSING,
|
|
129
|
-
`[dStorage/midnight] storeReference succeeded on-chain (txHash=${txHash}) but the runtime did not return the circuit refId at txData.private.result (got ${typeof circuitResult}). This is likely a compact-runtime version mismatch. Upgrade @midnight-ntwrk/compact-runtime or report this as a bug.`
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
this.logger?.debug?.(
|
|
133
|
-
"dStorage/midnight",
|
|
134
|
-
`transaction: circuit=storeReference txHash=${txHash} blockHeight=${blockHeight}`
|
|
135
|
-
);
|
|
136
|
-
return { refId: circuitResult, txHash, blockHeight };
|
|
137
|
-
} finally {
|
|
138
|
-
await this.providers.privateStateProvider.set(
|
|
139
|
-
dataRegistryPrivateStateKey,
|
|
140
|
-
{}
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
async removeReference(refId, ownerSecret) {
|
|
145
|
-
this.logger?.log(
|
|
146
|
-
"dStorage/midnight",
|
|
147
|
-
`removing reference: ${toHex(refId)}`
|
|
148
|
-
);
|
|
149
|
-
await this.providers.privateStateProvider.set(dataRegistryPrivateStateKey, {
|
|
150
|
-
ownerSecret: new Uint8Array(ownerSecret)
|
|
151
|
-
});
|
|
152
|
-
try {
|
|
153
|
-
const txData = await withContractScopedTransaction(
|
|
154
|
-
this.providers,
|
|
155
|
-
async (txCtx) => {
|
|
156
|
-
await this.deployedContract.callTx.removeReference(txCtx, refId);
|
|
157
|
-
},
|
|
158
|
-
{ scopeName: "removeReference" }
|
|
159
|
-
);
|
|
160
|
-
const txHash = txData.public.txHash ?? txData.public.txId ?? "";
|
|
161
|
-
const blockHeight = Number(txData.public.blockHeight ?? 0);
|
|
162
|
-
this.logger?.debug?.(
|
|
163
|
-
"dStorage/midnight",
|
|
164
|
-
`transaction: circuit=removeReference txHash=${txHash} blockHeight=${blockHeight}`
|
|
165
|
-
);
|
|
166
|
-
return { txHash, blockHeight };
|
|
167
|
-
} finally {
|
|
168
|
-
await this.providers.privateStateProvider.set(
|
|
169
|
-
dataRegistryPrivateStateKey,
|
|
170
|
-
{}
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
async updateReference(refId, storageId, encryptionScheme, storageProvider, metadata, writtenAt, keyEnvelope, contentHash, ownerSecret, newOwnerSecret) {
|
|
175
|
-
this.logger?.log(
|
|
176
|
-
"dStorage/midnight",
|
|
177
|
-
`updating reference: ${toHex(refId)}`
|
|
178
|
-
);
|
|
179
|
-
await this.providers.privateStateProvider.set(dataRegistryPrivateStateKey, {
|
|
180
|
-
ownerSecret: new Uint8Array(ownerSecret),
|
|
181
|
-
// When no new secret is provided, pass the old one so the circuit recomputes the same
|
|
182
|
-
// commitment and the stored value is preserved unchanged.
|
|
183
|
-
newOwnerSecret: new Uint8Array(newOwnerSecret ?? ownerSecret)
|
|
184
|
-
});
|
|
185
|
-
try {
|
|
186
|
-
const txData = await withContractScopedTransaction(
|
|
187
|
-
this.providers,
|
|
188
|
-
async (txCtx) => {
|
|
189
|
-
await this.deployedContract.callTx.updateReference(
|
|
190
|
-
txCtx,
|
|
191
|
-
refId,
|
|
192
|
-
storageId,
|
|
193
|
-
encryptionScheme,
|
|
194
|
-
storageProvider,
|
|
195
|
-
metadata,
|
|
196
|
-
writtenAt,
|
|
197
|
-
keyEnvelope,
|
|
198
|
-
contentHash
|
|
199
|
-
);
|
|
200
|
-
},
|
|
201
|
-
{ scopeName: "updateReference" }
|
|
202
|
-
);
|
|
203
|
-
const txHash = txData.public.txHash ?? txData.public.txId ?? "";
|
|
204
|
-
const blockHeight = Number(txData.public.blockHeight ?? 0);
|
|
205
|
-
this.logger?.debug?.(
|
|
206
|
-
"dStorage/midnight",
|
|
207
|
-
`transaction: circuit=updateReference txHash=${txHash} blockHeight=${blockHeight}`
|
|
208
|
-
);
|
|
209
|
-
return { txHash, blockHeight };
|
|
210
|
-
} finally {
|
|
211
|
-
await this.providers.privateStateProvider.set(
|
|
212
|
-
dataRegistryPrivateStateKey,
|
|
213
|
-
{}
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Deploys a new DataRegistry contract to the network.
|
|
219
|
-
*
|
|
220
|
-
* @param providers The DataRegistry providers.
|
|
221
|
-
* @param logger An optional 'pino' logger to use for logging.
|
|
222
|
-
* @returns A `Promise` that resolves with a {@link DataRegistryAPI} instance that manages the newly deployed
|
|
223
|
-
* {@link DeployedDataRegistryContract}; or rejects with a deployment error.
|
|
224
|
-
*/
|
|
225
|
-
static async deploy(providers, logger) {
|
|
226
|
-
logger?.log("dStorage/midnight", "deploying DataRegistry contract...");
|
|
227
|
-
const deployedDataRegistryContract = await deployContract(providers, {
|
|
228
|
-
compiledContract: CompiledDataRegistryContract,
|
|
229
|
-
privateStateId: dataRegistryPrivateStateKey,
|
|
230
|
-
initialPrivateState: createDataRegistryPrivateState()
|
|
231
|
-
});
|
|
232
|
-
return new _DataRegistryAPI(deployedDataRegistryContract, providers, logger);
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Finds an already deployed DataRegistry contract on the network, and joins it.
|
|
236
|
-
*
|
|
237
|
-
* @param providers The DataRegistry providers.
|
|
238
|
-
* @param contractAddress The contract address of the deployed DataRegistry contract to search for and join.
|
|
239
|
-
* @param logger An optional 'pino' logger to use for logging.
|
|
240
|
-
* @returns A `Promise` that resolves with a {@link DataRegistryAPI} instance that manages the joined
|
|
241
|
-
* {@link DeployedDataRegistryContract}; or rejects with an error.
|
|
242
|
-
*/
|
|
243
|
-
static async join(providers, contractAddress, logger) {
|
|
244
|
-
logger?.log(
|
|
245
|
-
"dStorage/midnight",
|
|
246
|
-
`joining DataRegistry contract at: ${contractAddress}`
|
|
247
|
-
);
|
|
248
|
-
providers.privateStateProvider.setContractAddress(contractAddress);
|
|
249
|
-
const deployedDataRegistryContract = await findDeployedContract(providers, {
|
|
250
|
-
contractAddress,
|
|
251
|
-
compiledContract: CompiledDataRegistryContract,
|
|
252
|
-
privateStateId: dataRegistryPrivateStateKey,
|
|
253
|
-
initialPrivateState: await _DataRegistryAPI.getPrivateState(providers)
|
|
254
|
-
});
|
|
255
|
-
const contractVersion = await (0, import_rxjs.firstValueFrom)(
|
|
256
|
-
providers.publicDataProvider.contractStateObservable(contractAddress, { type: "latest" }).pipe((0, import_rxjs.map)((s) => ledger(s.data).contractVersion))
|
|
257
|
-
);
|
|
258
|
-
validateContractVersion(contractVersion, contractAddress);
|
|
259
|
-
return new _DataRegistryAPI(deployedDataRegistryContract, providers, logger);
|
|
260
|
-
}
|
|
261
|
-
static async getPrivateState(providers) {
|
|
262
|
-
const existingPrivateState = await providers.privateStateProvider.get(
|
|
263
|
-
dataRegistryPrivateStateKey
|
|
264
|
-
);
|
|
265
|
-
return existingPrivateState ?? createDataRegistryPrivateState();
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
var randomBytes = (length) => {
|
|
269
|
-
const bytes = new Uint8Array(length);
|
|
270
|
-
crypto.getRandomValues(bytes);
|
|
271
|
-
return bytes;
|
|
272
|
-
};
|
|
273
|
-
export {
|
|
274
|
-
DataRegistryAPI,
|
|
275
|
-
SUPPORTED_CONTRACT_VERSION,
|
|
276
|
-
dataRegistryPrivateStateKey,
|
|
277
|
-
randomBytes,
|
|
278
|
-
validateContractVersion
|
|
279
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as v}from"./chunk-4YMF57VY.mjs";import{a as m}from"./chunk-EYF3263P.mjs";import{b as f,d as S,e as b}from"./chunk-TNRKN4LB.mjs";import"./chunk-ZGUY5EIR.mjs";import{H as P,Mb as H,P as x,V as R,Y as D,Zb as T}from"./chunk-Z2TH6U4C.mjs";import{deployContract as N,findDeployedContract as U,withContractScopedTransaction as w}from"@midnight-ntwrk/midnight-js-contracts";import{toHex as C}from"@midnight-ntwrk/midnight-js-utils";var o="DataRegistryPrivateState",$=0n;function k(h,t){if(h!==$)throw new m(v.CONTRACT_UNSUPPORTED_VERSION,`[dStorage/midnight] Unsupported contract version ${h} at ${t}. This SDK supports version ${$} only. Deploy a compatible DataRegistry contract or upgrade the SDK.`)}var j=class y{constructor(t,e,a){this.deployedContract=t,this.providers=e,this.logger=a,this.deployedContractAddress=t.deployTxData.public.contractAddress,this.state$=D([e.publicDataProvider.contractStateObservable(this.deployedContractAddress,{type:"latest"}).pipe(R(r=>f(r.data)),T(r=>a?.debug?.("dStorage/midnight",`ledger state changed: refCounter=${r.refCounter}`))),P(e.privateStateProvider.get(o))],(r,n)=>{let i=new Map;for(let[p,g]of r.references){let c=C(p);i.set(c,g)}return{references:i,refCounter:r.refCounter,contractVersion:r.contractVersion}}).pipe(H({bufferSize:1,refCount:!1}))}async storeReference(t,e,a,r,n,i,p,g){this.logger?.log("dStorage/midnight",`storing reference: storageId=${t}`),await this.providers.privateStateProvider.set(o,{ownerSecret:new Uint8Array(g)});try{let c=await w(this.providers,async u=>{await this.deployedContract.callTx.storeReference(u,t,e,a,r,n,i,p)},{scopeName:"storeReference"}),l=c.public.txHash??c.public.txId??"",s=Number(c.public.blockHeight??0),d=c.private.result;if(!(d instanceof Uint8Array))throw new m(v.CONTRACT_CIRCUIT_RESULT_MISSING,`[dStorage/midnight] storeReference succeeded on-chain (txHash=${l}) but the runtime did not return the circuit refId at txData.private.result (got ${typeof d}). This is likely a compact-runtime version mismatch. Upgrade @midnight-ntwrk/compact-runtime or report this as a bug.`);return this.logger?.debug?.("dStorage/midnight",`transaction: circuit=storeReference txHash=${l} blockHeight=${s}`),{refId:d,txHash:l,blockHeight:s}}finally{await this.providers.privateStateProvider.set(o,{})}}async removeReference(t,e){this.logger?.log("dStorage/midnight",`removing reference: ${C(t)}`),await this.providers.privateStateProvider.set(o,{ownerSecret:new Uint8Array(e)});try{let a=await w(this.providers,async i=>{await this.deployedContract.callTx.removeReference(i,t)},{scopeName:"removeReference"}),r=a.public.txHash??a.public.txId??"",n=Number(a.public.blockHeight??0);return this.logger?.debug?.("dStorage/midnight",`transaction: circuit=removeReference txHash=${r} blockHeight=${n}`),{txHash:r,blockHeight:n}}finally{await this.providers.privateStateProvider.set(o,{})}}async updateReference(t,e,a,r,n,i,p,g,c,l){this.logger?.log("dStorage/midnight",`updating reference: ${C(t)}`),await this.providers.privateStateProvider.set(o,{ownerSecret:new Uint8Array(c),newOwnerSecret:new Uint8Array(l??c)});try{let s=await w(this.providers,async I=>{await this.deployedContract.callTx.updateReference(I,t,e,a,r,n,i,p,g)},{scopeName:"updateReference"}),d=s.public.txHash??s.public.txId??"",u=Number(s.public.blockHeight??0);return this.logger?.debug?.("dStorage/midnight",`transaction: circuit=updateReference txHash=${d} blockHeight=${u}`),{txHash:d,blockHeight:u}}finally{await this.providers.privateStateProvider.set(o,{})}}static async deploy(t,e){e?.log("dStorage/midnight","deploying DataRegistry contract...");let a=await N(t,{compiledContract:b,privateStateId:o,initialPrivateState:S()});return new y(a,t,e)}static async join(t,e,a){a?.log("dStorage/midnight",`joining DataRegistry contract at: ${e}`),t.privateStateProvider.setContractAddress(e);let r=await U(t,{contractAddress:e,compiledContract:b,privateStateId:o,initialPrivateState:await y.getPrivateState(t)}),n=await x(t.publicDataProvider.contractStateObservable(e,{type:"latest"}).pipe(R(i=>f(i.data).contractVersion)));return k(n,e),new y(r,t,a)}static async getPrivateState(t){return await t.privateStateProvider.get(o)??S()}},L=h=>{let t=new Uint8Array(h);return crypto.getRandomValues(t),t};export{j as DataRegistryAPI,$ as SUPPORTED_CONTRACT_VERSION,o as dataRegistryPrivateStateKey,L as randomBytes,k as validateContractVersion};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as v}from"./chunk-4YMF57VY.mjs";import{a as m}from"./chunk-EYF3263P.mjs";import{b as f,d as S,e as b}from"./chunk-TNRKN4LB.mjs";import{H as P,Mb as H,P as x,V as R,Y as D,Zb as T}from"./chunk-Z2TH6U4C.mjs";import"./chunk-ZGUY5EIR.mjs";import{deployContract as N,findDeployedContract as U,withContractScopedTransaction as w}from"@midnight-ntwrk/midnight-js-contracts";import{toHex as C}from"@midnight-ntwrk/midnight-js-utils";var o="DataRegistryPrivateState",$=0n;function k(h,t){if(h!==$)throw new m(v.CONTRACT_UNSUPPORTED_VERSION,`[dStorage/midnight] Unsupported contract version ${h} at ${t}. This SDK supports version ${$} only. Deploy a compatible DataRegistry contract or upgrade the SDK.`)}var j=class y{constructor(t,e,a){this.deployedContract=t,this.providers=e,this.logger=a,this.deployedContractAddress=t.deployTxData.public.contractAddress,this.state$=D([e.publicDataProvider.contractStateObservable(this.deployedContractAddress,{type:"latest"}).pipe(R(r=>f(r.data)),T(r=>a?.debug?.("dStorage/midnight",`ledger state changed: refCounter=${r.refCounter}`))),P(e.privateStateProvider.get(o))],(r,n)=>{let i=new Map;for(let[p,g]of r.references){let c=C(p);i.set(c,g)}return{references:i,refCounter:r.refCounter,contractVersion:r.contractVersion}}).pipe(H({bufferSize:1,refCount:!1}))}async storeReference(t,e,a,r,n,i,p,g){this.logger?.log("dStorage/midnight",`storing reference: storageId=${t}`),await this.providers.privateStateProvider.set(o,{ownerSecret:new Uint8Array(g)});try{let c=await w(this.providers,async u=>{await this.deployedContract.callTx.storeReference(u,t,e,a,r,n,i,p)},{scopeName:"storeReference"}),l=c.public.txHash??c.public.txId??"",s=Number(c.public.blockHeight??0),d=c.private.result;if(!(d instanceof Uint8Array))throw new m(v.CONTRACT_CIRCUIT_RESULT_MISSING,`[dStorage/midnight] storeReference succeeded on-chain (txHash=${l}) but the runtime did not return the circuit refId at txData.private.result (got ${typeof d}). This is likely a compact-runtime version mismatch. Upgrade @midnight-ntwrk/compact-runtime or report this as a bug.`);return this.logger?.debug?.("dStorage/midnight",`transaction: circuit=storeReference txHash=${l} blockHeight=${s}`),{refId:d,txHash:l,blockHeight:s}}finally{await this.providers.privateStateProvider.set(o,{})}}async removeReference(t,e){this.logger?.log("dStorage/midnight",`removing reference: ${C(t)}`),await this.providers.privateStateProvider.set(o,{ownerSecret:new Uint8Array(e)});try{let a=await w(this.providers,async i=>{await this.deployedContract.callTx.removeReference(i,t)},{scopeName:"removeReference"}),r=a.public.txHash??a.public.txId??"",n=Number(a.public.blockHeight??0);return this.logger?.debug?.("dStorage/midnight",`transaction: circuit=removeReference txHash=${r} blockHeight=${n}`),{txHash:r,blockHeight:n}}finally{await this.providers.privateStateProvider.set(o,{})}}async updateReference(t,e,a,r,n,i,p,g,c,l){this.logger?.log("dStorage/midnight",`updating reference: ${C(t)}`),await this.providers.privateStateProvider.set(o,{ownerSecret:new Uint8Array(c),newOwnerSecret:new Uint8Array(l??c)});try{let s=await w(this.providers,async I=>{await this.deployedContract.callTx.updateReference(I,t,e,a,r,n,i,p,g)},{scopeName:"updateReference"}),d=s.public.txHash??s.public.txId??"",u=Number(s.public.blockHeight??0);return this.logger?.debug?.("dStorage/midnight",`transaction: circuit=updateReference txHash=${d} blockHeight=${u}`),{txHash:d,blockHeight:u}}finally{await this.providers.privateStateProvider.set(o,{})}}static async deploy(t,e){e?.log("dStorage/midnight","deploying DataRegistry contract...");let a=await N(t,{compiledContract:b,privateStateId:o,initialPrivateState:S()});return new y(a,t,e)}static async join(t,e,a){a?.log("dStorage/midnight",`joining DataRegistry contract at: ${e}`),t.privateStateProvider.setContractAddress(e);let r=await U(t,{contractAddress:e,compiledContract:b,privateStateId:o,initialPrivateState:await y.getPrivateState(t)}),n=await x(t.publicDataProvider.contractStateObservable(e,{type:"latest"}).pipe(R(i=>f(i.data).contractVersion)));return k(n,e),new y(r,t,a)}static async getPrivateState(t){return await t.privateStateProvider.get(o)??S()}},L=h=>{let t=new Uint8Array(h);return crypto.getRandomValues(t),t};export{j as DataRegistryAPI,$ as SUPPORTED_CONTRACT_VERSION,o as dataRegistryPrivateStateKey,L as randomBytes,k as validateContractVersion};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as v}from"./chunk-4YMF57VY.mjs";import{a as m}from"./chunk-UBALMYIY.mjs";import{b as f,d as S,e as b}from"./chunk-TNRKN4LB.mjs";import"./chunk-ZGUY5EIR.mjs";import{H as P,Mb as H,P as x,V as R,Y as D,Zb as T}from"./chunk-Z2TH6U4C.mjs";import{deployContract as N,findDeployedContract as U,withContractScopedTransaction as w}from"@midnight-ntwrk/midnight-js-contracts";import{toHex as C}from"@midnight-ntwrk/midnight-js-utils";var o="DataRegistryPrivateState",$=0n;function k(h,t){if(h!==$)throw new m(v.CONTRACT_UNSUPPORTED_VERSION,`[dStorage/midnight] Unsupported contract version ${h} at ${t}. This SDK supports version ${$} only. Deploy a compatible DataRegistry contract or upgrade the SDK.`)}var j=class y{constructor(t,e,a){this.deployedContract=t,this.providers=e,this.logger=a,this.deployedContractAddress=t.deployTxData.public.contractAddress,this.state$=D([e.publicDataProvider.contractStateObservable(this.deployedContractAddress,{type:"latest"}).pipe(R(r=>f(r.data)),T(r=>a?.debug?.("dStorage/midnight",`ledger state changed: refCounter=${r.refCounter}`))),P(e.privateStateProvider.get(o))],(r,n)=>{let i=new Map;for(let[p,g]of r.references){let c=C(p);i.set(c,g)}return{references:i,refCounter:r.refCounter,contractVersion:r.contractVersion}}).pipe(H({bufferSize:1,refCount:!1}))}async storeReference(t,e,a,r,n,i,p,g){this.logger?.log("dStorage/midnight",`storing reference: storageId=${t}`),await this.providers.privateStateProvider.set(o,{ownerSecret:new Uint8Array(g)});try{let c=await w(this.providers,async u=>{await this.deployedContract.callTx.storeReference(u,t,e,a,r,n,i,p)},{scopeName:"storeReference"}),l=c.public.txHash??c.public.txId??"",s=Number(c.public.blockHeight??0),d=c.private.result;if(!(d instanceof Uint8Array))throw new m(v.CONTRACT_CIRCUIT_RESULT_MISSING,`[dStorage/midnight] storeReference succeeded on-chain (txHash=${l}) but the runtime did not return the circuit refId at txData.private.result (got ${typeof d}). This is likely a compact-runtime version mismatch. Upgrade @midnight-ntwrk/compact-runtime or report this as a bug.`);return this.logger?.debug?.("dStorage/midnight",`transaction: circuit=storeReference txHash=${l} blockHeight=${s}`),{refId:d,txHash:l,blockHeight:s}}finally{await this.providers.privateStateProvider.set(o,{})}}async removeReference(t,e){this.logger?.log("dStorage/midnight",`removing reference: ${C(t)}`),await this.providers.privateStateProvider.set(o,{ownerSecret:new Uint8Array(e)});try{let a=await w(this.providers,async i=>{await this.deployedContract.callTx.removeReference(i,t)},{scopeName:"removeReference"}),r=a.public.txHash??a.public.txId??"",n=Number(a.public.blockHeight??0);return this.logger?.debug?.("dStorage/midnight",`transaction: circuit=removeReference txHash=${r} blockHeight=${n}`),{txHash:r,blockHeight:n}}finally{await this.providers.privateStateProvider.set(o,{})}}async updateReference(t,e,a,r,n,i,p,g,c,l){this.logger?.log("dStorage/midnight",`updating reference: ${C(t)}`),await this.providers.privateStateProvider.set(o,{ownerSecret:new Uint8Array(c),newOwnerSecret:new Uint8Array(l??c)});try{let s=await w(this.providers,async I=>{await this.deployedContract.callTx.updateReference(I,t,e,a,r,n,i,p,g)},{scopeName:"updateReference"}),d=s.public.txHash??s.public.txId??"",u=Number(s.public.blockHeight??0);return this.logger?.debug?.("dStorage/midnight",`transaction: circuit=updateReference txHash=${d} blockHeight=${u}`),{txHash:d,blockHeight:u}}finally{await this.providers.privateStateProvider.set(o,{})}}static async deploy(t,e){e?.log("dStorage/midnight","deploying DataRegistry contract...");let a=await N(t,{compiledContract:b,privateStateId:o,initialPrivateState:S()});return new y(a,t,e)}static async join(t,e,a){a?.log("dStorage/midnight",`joining DataRegistry contract at: ${e}`),t.privateStateProvider.setContractAddress(e);let r=await U(t,{contractAddress:e,compiledContract:b,privateStateId:o,initialPrivateState:await y.getPrivateState(t)}),n=await x(t.publicDataProvider.contractStateObservable(e,{type:"latest"}).pipe(R(i=>f(i.data).contractVersion)));return k(n,e),new y(r,t,a)}static async getPrivateState(t){return await t.privateStateProvider.get(o)??S()}},L=h=>{let t=new Uint8Array(h);return crypto.getRandomValues(t),t};export{j as DataRegistryAPI,$ as SUPPORTED_CONTRACT_VERSION,o as dataRegistryPrivateStateKey,L as randomBytes,k as validateContractVersion};
|
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChainErrorCode
|
|
3
|
-
} from "./chunk-JMPRZK5D.mjs";
|
|
4
|
-
import {
|
|
5
|
-
DStorageError
|
|
6
|
-
} from "./chunk-BWLEAAFW.mjs";
|
|
7
|
-
import {
|
|
8
|
-
CompiledDataRegistryContract,
|
|
9
|
-
createDataRegistryPrivateState,
|
|
10
|
-
ledger
|
|
11
|
-
} from "./chunk-VDZ7F7MP.mjs";
|
|
12
|
-
import "./chunk-5QOKJEH3.mjs";
|
|
13
|
-
import {
|
|
14
|
-
require_cjs
|
|
15
|
-
} from "./chunk-25I6ZXUC.mjs";
|
|
16
|
-
import {
|
|
17
|
-
__toESM
|
|
18
|
-
} from "./chunk-UJCSKKID.mjs";
|
|
19
|
-
|
|
20
|
-
// ../chain/dist/contract-api-TJ7JPHZA.mjs
|
|
21
|
-
var import_rxjs = __toESM(require_cjs(), 1);
|
|
22
|
-
import {
|
|
23
|
-
deployContract,
|
|
24
|
-
findDeployedContract,
|
|
25
|
-
withContractScopedTransaction
|
|
26
|
-
} from "@midnight-ntwrk/midnight-js-contracts";
|
|
27
|
-
import { toHex } from "@midnight-ntwrk/midnight-js-utils";
|
|
28
|
-
var dataRegistryPrivateStateKey = "DataRegistryPrivateState";
|
|
29
|
-
var SUPPORTED_CONTRACT_VERSION = 0n;
|
|
30
|
-
function validateContractVersion(version, contractAddress) {
|
|
31
|
-
if (version !== SUPPORTED_CONTRACT_VERSION) {
|
|
32
|
-
throw new DStorageError(
|
|
33
|
-
ChainErrorCode.CONTRACT_UNSUPPORTED_VERSION,
|
|
34
|
-
`[dStorage/midnight] Unsupported contract version ${version} at ${contractAddress}. This SDK supports version ${SUPPORTED_CONTRACT_VERSION} only. Deploy a compatible DataRegistry contract or upgrade the SDK.`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
var DataRegistryAPI = class _DataRegistryAPI {
|
|
39
|
-
/** @internal */
|
|
40
|
-
constructor(deployedContract, providers, logger) {
|
|
41
|
-
this.deployedContract = deployedContract;
|
|
42
|
-
this.providers = providers;
|
|
43
|
-
this.logger = logger;
|
|
44
|
-
this.deployedContractAddress = deployedContract.deployTxData.public.contractAddress;
|
|
45
|
-
this.state$ = (0, import_rxjs.combineLatest)(
|
|
46
|
-
[
|
|
47
|
-
// Combine public (ledger) state with...
|
|
48
|
-
providers.publicDataProvider.contractStateObservable(this.deployedContractAddress, {
|
|
49
|
-
type: "latest"
|
|
50
|
-
}).pipe(
|
|
51
|
-
(0, import_rxjs.map)((contractState) => ledger(contractState.data)),
|
|
52
|
-
(0, import_rxjs.tap)(
|
|
53
|
-
(ledgerState) => logger?.debug?.(
|
|
54
|
-
"dStorage/midnight",
|
|
55
|
-
`ledger state changed: refCounter=${ledgerState.refCounter}`
|
|
56
|
-
)
|
|
57
|
-
)
|
|
58
|
-
),
|
|
59
|
-
// ...private state...
|
|
60
|
-
// since the private state of the DataRegistry application never changes, we can query the
|
|
61
|
-
// private state once and always use the same value with `combineLatest`. In applications
|
|
62
|
-
// where the private state is expected to change, we would need to make this an `Observable`.
|
|
63
|
-
(0, import_rxjs.from)(
|
|
64
|
-
providers.privateStateProvider.get(
|
|
65
|
-
dataRegistryPrivateStateKey
|
|
66
|
-
)
|
|
67
|
-
)
|
|
68
|
-
],
|
|
69
|
-
// ...and combine them to produce the required derived state.
|
|
70
|
-
// isOurs is set to false here — ownership is determined by the core SDK
|
|
71
|
-
// (dStorage.ts) by attempting to unwrap the DEK from the keyEnvelope using
|
|
72
|
-
// the available KEKs. This avoids coupling the chain layer to key material.
|
|
73
|
-
(ledgerState, _privateState) => {
|
|
74
|
-
const references = /* @__PURE__ */ new Map();
|
|
75
|
-
for (const [id, refEntry] of ledgerState.references) {
|
|
76
|
-
const refId = toHex(id);
|
|
77
|
-
references.set(refId, refEntry);
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
references,
|
|
81
|
-
refCounter: ledgerState.refCounter,
|
|
82
|
-
contractVersion: ledgerState.contractVersion
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
).pipe(
|
|
86
|
-
// Keep one live subscription to the indexer WebSocket for the lifetime of
|
|
87
|
-
// this API instance. Without shareReplay, each firstValueFrom(state$) call
|
|
88
|
-
// creates a new subscription — the indexer does not replay the last emitted
|
|
89
|
-
// state to new subscribers, so callers would receive stale data until the
|
|
90
|
-
// next on-chain change arrives. shareReplay(1) ensures:
|
|
91
|
-
// 1. The indexer connection is established once and kept alive.
|
|
92
|
-
// 2. Every new subscriber (e.g. listReferences, readReference) immediately
|
|
93
|
-
// receives the most recently emitted state.
|
|
94
|
-
// 3. Future indexer pushes (after upload/remove txs) still update the cache.
|
|
95
|
-
(0, import_rxjs.shareReplay)({ bufferSize: 1, refCount: false })
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
async storeReference(storageId, encryptionScheme, storageProvider, metadata, writtenAt, keyEnvelope, contentHash, ownerSecret) {
|
|
99
|
-
this.logger?.log(
|
|
100
|
-
"dStorage/midnight",
|
|
101
|
-
`storing reference: storageId=${storageId}`
|
|
102
|
-
);
|
|
103
|
-
await this.providers.privateStateProvider.set(dataRegistryPrivateStateKey, {
|
|
104
|
-
ownerSecret: new Uint8Array(ownerSecret)
|
|
105
|
-
});
|
|
106
|
-
try {
|
|
107
|
-
const txData = await withContractScopedTransaction(
|
|
108
|
-
this.providers,
|
|
109
|
-
async (txCtx) => {
|
|
110
|
-
await this.deployedContract.callTx.storeReference(
|
|
111
|
-
txCtx,
|
|
112
|
-
storageId,
|
|
113
|
-
encryptionScheme,
|
|
114
|
-
storageProvider,
|
|
115
|
-
metadata,
|
|
116
|
-
writtenAt,
|
|
117
|
-
keyEnvelope,
|
|
118
|
-
contentHash
|
|
119
|
-
);
|
|
120
|
-
},
|
|
121
|
-
{ scopeName: "storeReference" }
|
|
122
|
-
);
|
|
123
|
-
const txHash = txData.public.txHash ?? txData.public.txId ?? "";
|
|
124
|
-
const blockHeight = Number(txData.public.blockHeight ?? 0);
|
|
125
|
-
const circuitResult = txData.private.result;
|
|
126
|
-
if (!(circuitResult instanceof Uint8Array)) {
|
|
127
|
-
throw new DStorageError(
|
|
128
|
-
ChainErrorCode.CONTRACT_CIRCUIT_RESULT_MISSING,
|
|
129
|
-
`[dStorage/midnight] storeReference succeeded on-chain (txHash=${txHash}) but the runtime did not return the circuit refId at txData.private.result (got ${typeof circuitResult}). This is likely a compact-runtime version mismatch. Upgrade @midnight-ntwrk/compact-runtime or report this as a bug.`
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
this.logger?.debug?.(
|
|
133
|
-
"dStorage/midnight",
|
|
134
|
-
`transaction: circuit=storeReference txHash=${txHash} blockHeight=${blockHeight}`
|
|
135
|
-
);
|
|
136
|
-
return { refId: circuitResult, txHash, blockHeight };
|
|
137
|
-
} finally {
|
|
138
|
-
await this.providers.privateStateProvider.set(
|
|
139
|
-
dataRegistryPrivateStateKey,
|
|
140
|
-
{}
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
async removeReference(refId, ownerSecret) {
|
|
145
|
-
this.logger?.log(
|
|
146
|
-
"dStorage/midnight",
|
|
147
|
-
`removing reference: ${toHex(refId)}`
|
|
148
|
-
);
|
|
149
|
-
await this.providers.privateStateProvider.set(dataRegistryPrivateStateKey, {
|
|
150
|
-
ownerSecret: new Uint8Array(ownerSecret)
|
|
151
|
-
});
|
|
152
|
-
try {
|
|
153
|
-
const txData = await withContractScopedTransaction(
|
|
154
|
-
this.providers,
|
|
155
|
-
async (txCtx) => {
|
|
156
|
-
await this.deployedContract.callTx.removeReference(txCtx, refId);
|
|
157
|
-
},
|
|
158
|
-
{ scopeName: "removeReference" }
|
|
159
|
-
);
|
|
160
|
-
const txHash = txData.public.txHash ?? txData.public.txId ?? "";
|
|
161
|
-
const blockHeight = Number(txData.public.blockHeight ?? 0);
|
|
162
|
-
this.logger?.debug?.(
|
|
163
|
-
"dStorage/midnight",
|
|
164
|
-
`transaction: circuit=removeReference txHash=${txHash} blockHeight=${blockHeight}`
|
|
165
|
-
);
|
|
166
|
-
return { txHash, blockHeight };
|
|
167
|
-
} finally {
|
|
168
|
-
await this.providers.privateStateProvider.set(
|
|
169
|
-
dataRegistryPrivateStateKey,
|
|
170
|
-
{}
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
async updateReference(refId, storageId, encryptionScheme, storageProvider, metadata, writtenAt, keyEnvelope, contentHash, ownerSecret, newOwnerSecret) {
|
|
175
|
-
this.logger?.log(
|
|
176
|
-
"dStorage/midnight",
|
|
177
|
-
`updating reference: ${toHex(refId)}`
|
|
178
|
-
);
|
|
179
|
-
await this.providers.privateStateProvider.set(dataRegistryPrivateStateKey, {
|
|
180
|
-
ownerSecret: new Uint8Array(ownerSecret),
|
|
181
|
-
// When no new secret is provided, pass the old one so the circuit recomputes the same
|
|
182
|
-
// commitment and the stored value is preserved unchanged.
|
|
183
|
-
newOwnerSecret: new Uint8Array(newOwnerSecret ?? ownerSecret)
|
|
184
|
-
});
|
|
185
|
-
try {
|
|
186
|
-
const txData = await withContractScopedTransaction(
|
|
187
|
-
this.providers,
|
|
188
|
-
async (txCtx) => {
|
|
189
|
-
await this.deployedContract.callTx.updateReference(
|
|
190
|
-
txCtx,
|
|
191
|
-
refId,
|
|
192
|
-
storageId,
|
|
193
|
-
encryptionScheme,
|
|
194
|
-
storageProvider,
|
|
195
|
-
metadata,
|
|
196
|
-
writtenAt,
|
|
197
|
-
keyEnvelope,
|
|
198
|
-
contentHash
|
|
199
|
-
);
|
|
200
|
-
},
|
|
201
|
-
{ scopeName: "updateReference" }
|
|
202
|
-
);
|
|
203
|
-
const txHash = txData.public.txHash ?? txData.public.txId ?? "";
|
|
204
|
-
const blockHeight = Number(txData.public.blockHeight ?? 0);
|
|
205
|
-
this.logger?.debug?.(
|
|
206
|
-
"dStorage/midnight",
|
|
207
|
-
`transaction: circuit=updateReference txHash=${txHash} blockHeight=${blockHeight}`
|
|
208
|
-
);
|
|
209
|
-
return { txHash, blockHeight };
|
|
210
|
-
} finally {
|
|
211
|
-
await this.providers.privateStateProvider.set(
|
|
212
|
-
dataRegistryPrivateStateKey,
|
|
213
|
-
{}
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Deploys a new DataRegistry contract to the network.
|
|
219
|
-
*
|
|
220
|
-
* @param providers The DataRegistry providers.
|
|
221
|
-
* @param logger An optional 'pino' logger to use for logging.
|
|
222
|
-
* @returns A `Promise` that resolves with a {@link DataRegistryAPI} instance that manages the newly deployed
|
|
223
|
-
* {@link DeployedDataRegistryContract}; or rejects with a deployment error.
|
|
224
|
-
*/
|
|
225
|
-
static async deploy(providers, logger) {
|
|
226
|
-
logger?.log("dStorage/midnight", "deploying DataRegistry contract...");
|
|
227
|
-
const deployedDataRegistryContract = await deployContract(providers, {
|
|
228
|
-
compiledContract: CompiledDataRegistryContract,
|
|
229
|
-
privateStateId: dataRegistryPrivateStateKey,
|
|
230
|
-
initialPrivateState: createDataRegistryPrivateState()
|
|
231
|
-
});
|
|
232
|
-
return new _DataRegistryAPI(deployedDataRegistryContract, providers, logger);
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Finds an already deployed DataRegistry contract on the network, and joins it.
|
|
236
|
-
*
|
|
237
|
-
* @param providers The DataRegistry providers.
|
|
238
|
-
* @param contractAddress The contract address of the deployed DataRegistry contract to search for and join.
|
|
239
|
-
* @param logger An optional 'pino' logger to use for logging.
|
|
240
|
-
* @returns A `Promise` that resolves with a {@link DataRegistryAPI} instance that manages the joined
|
|
241
|
-
* {@link DeployedDataRegistryContract}; or rejects with an error.
|
|
242
|
-
*/
|
|
243
|
-
static async join(providers, contractAddress, logger) {
|
|
244
|
-
logger?.log(
|
|
245
|
-
"dStorage/midnight",
|
|
246
|
-
`joining DataRegistry contract at: ${contractAddress}`
|
|
247
|
-
);
|
|
248
|
-
providers.privateStateProvider.setContractAddress(contractAddress);
|
|
249
|
-
const deployedDataRegistryContract = await findDeployedContract(providers, {
|
|
250
|
-
contractAddress,
|
|
251
|
-
compiledContract: CompiledDataRegistryContract,
|
|
252
|
-
privateStateId: dataRegistryPrivateStateKey,
|
|
253
|
-
initialPrivateState: await _DataRegistryAPI.getPrivateState(providers)
|
|
254
|
-
});
|
|
255
|
-
const contractVersion = await (0, import_rxjs.firstValueFrom)(
|
|
256
|
-
providers.publicDataProvider.contractStateObservable(contractAddress, { type: "latest" }).pipe((0, import_rxjs.map)((s) => ledger(s.data).contractVersion))
|
|
257
|
-
);
|
|
258
|
-
validateContractVersion(contractVersion, contractAddress);
|
|
259
|
-
return new _DataRegistryAPI(deployedDataRegistryContract, providers, logger);
|
|
260
|
-
}
|
|
261
|
-
static async getPrivateState(providers) {
|
|
262
|
-
const existingPrivateState = await providers.privateStateProvider.get(
|
|
263
|
-
dataRegistryPrivateStateKey
|
|
264
|
-
);
|
|
265
|
-
return existingPrivateState ?? createDataRegistryPrivateState();
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
var randomBytes = (length) => {
|
|
269
|
-
const bytes = new Uint8Array(length);
|
|
270
|
-
crypto.getRandomValues(bytes);
|
|
271
|
-
return bytes;
|
|
272
|
-
};
|
|
273
|
-
export {
|
|
274
|
-
DataRegistryAPI,
|
|
275
|
-
SUPPORTED_CONTRACT_VERSION,
|
|
276
|
-
dataRegistryPrivateStateKey,
|
|
277
|
-
randomBytes,
|
|
278
|
-
validateContractVersion
|
|
279
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as C,b as m,c as l,d as u}from"./chunk-TNRKN4LB.mjs";import"./chunk-ZGUY5EIR.mjs";import{QueryContext as S,sampleContractAddress as d,createConstructorContext as w,emptyZswapLocalState as p,CostModel as f}from"@midnight-ntwrk/compact-runtime";var R=class{constructor(t){this._defaultOwnerSecret=crypto.getRandomValues(new Uint8Array(32)),this.contractAddress=d(),this.contract=new C(l),this.currentPk=t;let{currentPrivateState:r,currentContractState:e,currentZswapLocalState:c}=this.contract.initialState(w(u(),t));this.circuitContext={currentPrivateState:r,currentZswapLocalState:c,costModel:f.initialCostModel(),currentQueryContext:new S(e.data,this.contractAddress)}}switchUser(t){this.currentPk=t,this.circuitContext.currentZswapLocalState=p(t),this.circuitContext.currentPrivateState=u(),this._defaultOwnerSecret=crypto.getRandomValues(new Uint8Array(32))}getLedger(){return m(this.circuitContext.currentQueryContext.state)}storeReference(t,r,e,c,n,a="",s=new Uint8Array(32),o=this._defaultOwnerSecret){this.circuitContext.currentPrivateState={ownerSecret:o};let i=this.contract.impureCircuits.storeReference(this.circuitContext,t,r,e,c,n,a,s);return this.circuitContext={...i.context,currentPrivateState:{}},i.result}removeReference(t,r=this._defaultOwnerSecret){this.circuitContext.currentPrivateState={ownerSecret:r};let e=this.contract.impureCircuits.removeReference(this.circuitContext,t);return this.circuitContext={...e.context,currentPrivateState:{}},e.result}computeOwnerCommitment(t,r,e){return this.contract._computeOwnerCommitment_0(t,r,e)}updateReference(t,r,e,c,n,a,s="",o=new Uint8Array(32),i=this._defaultOwnerSecret,x){this.circuitContext.currentPrivateState={ownerSecret:i,newOwnerSecret:x??i};let h=this.contract.impureCircuits.updateReference(this.circuitContext,t,r,e,c,n,a,s,o);return this.circuitContext={...h.context,currentPrivateState:{}},h.result}};export{R as DataRegistrySimulator};
|
package/dist/dist-655VYUPJ.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{A,B,C,D,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-UBALMYIY.mjs";export{c as CryptoErrorCode,a as DStorageError,f as KeyDeriver,o as XChaChaScheme,d as base64urlToBytes,u as buildKeyEnvelope,e as bytesToBase64url,C as computeBlake3,D as computeBlake3Hex,l as decryptStorageIdXChaCha,j as decryptXChaCha,q as deriveKek,t as deriveOwnerSecret,h as deriveSymmetricKeyFromSeed,n as deserializeXChaChaPayload,k as encryptStorageIdXChaCha,i as encryptXChaCha,x as findWrapper,p as generateDek,g as hexToBytes,b as isDStorageError,y as mlkemGenerateKeypair,z as mlkemGenerateKeypairFromSeed,B as mlkemUnwrapDek,A as mlkemWrapDek,w as parseKeyEnvelope,v as serializeKeyEnvelope,m as serializeXChaChaPayload,s as unwrapKey,r as wrapKey};
|
package/dist/dist-MEZZWKP4.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{A,B,C,D,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-EYF3263P.mjs";export{c as CryptoErrorCode,a as DStorageError,f as KeyDeriver,o as XChaChaScheme,d as base64urlToBytes,u as buildKeyEnvelope,e as bytesToBase64url,C as computeBlake3,D as computeBlake3Hex,l as decryptStorageIdXChaCha,j as decryptXChaCha,q as deriveKek,t as deriveOwnerSecret,h as deriveSymmetricKeyFromSeed,n as deserializeXChaChaPayload,k as encryptStorageIdXChaCha,i as encryptXChaCha,x as findWrapper,p as generateDek,g as hexToBytes,b as isDStorageError,y as mlkemGenerateKeypair,z as mlkemGenerateKeypairFromSeed,B as mlkemUnwrapDek,A as mlkemWrapDek,w as parseKeyEnvelope,v as serializeKeyEnvelope,m as serializeXChaChaPayload,s as unwrapKey,r as wrapKey};
|
package/dist/dist-UD4WRMYJ.mjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CryptoErrorCode,
|
|
3
|
-
DStorageError,
|
|
4
|
-
KeyDeriver,
|
|
5
|
-
XChaChaScheme,
|
|
6
|
-
base64urlToBytes,
|
|
7
|
-
buildKeyEnvelope,
|
|
8
|
-
bytesToBase64url,
|
|
9
|
-
computeBlake3,
|
|
10
|
-
computeBlake3Hex,
|
|
11
|
-
decryptStorageIdXChaCha,
|
|
12
|
-
decryptXChaCha,
|
|
13
|
-
deriveKek,
|
|
14
|
-
deriveOwnerSecret,
|
|
15
|
-
deriveSymmetricKeyFromSeed,
|
|
16
|
-
deserializeXChaChaPayload,
|
|
17
|
-
encryptStorageIdXChaCha,
|
|
18
|
-
encryptXChaCha,
|
|
19
|
-
findWrapper,
|
|
20
|
-
generateDek,
|
|
21
|
-
hexToBytes,
|
|
22
|
-
isDStorageError,
|
|
23
|
-
mlkemGenerateKeypair,
|
|
24
|
-
mlkemGenerateKeypairFromSeed,
|
|
25
|
-
mlkemUnwrapDek,
|
|
26
|
-
mlkemWrapDek,
|
|
27
|
-
parseKeyEnvelope,
|
|
28
|
-
serializeKeyEnvelope,
|
|
29
|
-
serializeXChaChaPayload,
|
|
30
|
-
unwrapKey,
|
|
31
|
-
wrapKey
|
|
32
|
-
} from "./chunk-TSZ37JDY.mjs";
|
|
33
|
-
import "./chunk-UJCSKKID.mjs";
|
|
34
|
-
export {
|
|
35
|
-
CryptoErrorCode,
|
|
36
|
-
DStorageError,
|
|
37
|
-
KeyDeriver,
|
|
38
|
-
XChaChaScheme,
|
|
39
|
-
base64urlToBytes,
|
|
40
|
-
buildKeyEnvelope,
|
|
41
|
-
bytesToBase64url,
|
|
42
|
-
computeBlake3,
|
|
43
|
-
computeBlake3Hex,
|
|
44
|
-
decryptStorageIdXChaCha,
|
|
45
|
-
decryptXChaCha,
|
|
46
|
-
deriveKek,
|
|
47
|
-
deriveOwnerSecret,
|
|
48
|
-
deriveSymmetricKeyFromSeed,
|
|
49
|
-
deserializeXChaChaPayload,
|
|
50
|
-
encryptStorageIdXChaCha,
|
|
51
|
-
encryptXChaCha,
|
|
52
|
-
findWrapper,
|
|
53
|
-
generateDek,
|
|
54
|
-
hexToBytes,
|
|
55
|
-
isDStorageError,
|
|
56
|
-
mlkemGenerateKeypair,
|
|
57
|
-
mlkemGenerateKeypairFromSeed,
|
|
58
|
-
mlkemUnwrapDek,
|
|
59
|
-
mlkemWrapDek,
|
|
60
|
-
parseKeyEnvelope,
|
|
61
|
-
serializeKeyEnvelope,
|
|
62
|
-
serializeXChaChaPayload,
|
|
63
|
-
unwrapKey,
|
|
64
|
-
wrapKey
|
|
65
|
-
};
|