@calimero-network/mero-js 22.9.0 → 23.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/admin-api/admin-client.d.ts +22 -2
- package/dist/admin-api/admin-client.js +38 -2
- package/dist/admin-api/admin-types.d.ts +63 -1
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +358 -16
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -1
- package/dist/index.mjs +358 -16
- package/dist/index.mjs.map +4 -4
- package/dist/namespace-op/namespace-op.d.ts +19 -1
- package/dist/namespace-op/namespace-op.js +19 -1
- package/dist/owner-op/index.d.ts +2 -0
- package/dist/owner-op/index.js +3 -0
- package/dist/owner-op/owner-op.d.ts +119 -0
- package/dist/owner-op/owner-op.js +214 -0
- package/dist/warrant/governance-op.d.ts +67 -1
- package/dist/warrant/governance-op.js +145 -1
- package/dist/warrant/index.d.ts +2 -2
- package/dist/warrant/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
MeroClient: () => MeroClient,
|
|
39
39
|
MeroJs: () => MeroJs,
|
|
40
40
|
NODE_RELEASE_SIGNER: () => NODE_RELEASE_SIGNER,
|
|
41
|
+
OWNER_OP_KIND: () => OWNER_OP_KIND,
|
|
41
42
|
REQUEST_PROOF_HEADER: () => REQUEST_PROOF_HEADER,
|
|
42
43
|
RelayClient: () => RelayClient,
|
|
43
44
|
RelayObserver: () => RelayObserver,
|
|
@@ -59,6 +60,7 @@ __export(index_exports, {
|
|
|
59
60
|
accountRootFromPhrase: () => accountRootFromPhrase,
|
|
60
61
|
accountRootFromSecret: () => accountRootFromSecret,
|
|
61
62
|
accountRootSignerFromPhrase: () => accountRootSignerFromPhrase,
|
|
63
|
+
adminChangedOp: () => adminChangedOp,
|
|
62
64
|
admitterAddrsFromNetworkStatus: () => admitterAddrsFromNetworkStatus,
|
|
63
65
|
attestKeyBinding: () => attestKeyBinding,
|
|
64
66
|
attestRelayNodeKey: () => attestRelayNodeKey,
|
|
@@ -79,6 +81,10 @@ __export(index_exports, {
|
|
|
79
81
|
completeDeviceEnrolment: () => completeDeviceEnrolment,
|
|
80
82
|
connectCloud: () => connectCloud,
|
|
81
83
|
connectCloudWithAccount: () => connectCloudWithAccount,
|
|
84
|
+
contextCapabilityGrantedOp: () => contextCapabilityGrantedOp,
|
|
85
|
+
contextCapabilityRevokedOp: () => contextCapabilityRevokedOp,
|
|
86
|
+
contextDetachedOp: () => contextDetachedOp,
|
|
87
|
+
contextMetadataSetOp: () => contextMetadataSetOp,
|
|
82
88
|
createAccountRootSigner: () => createAccountRootSigner,
|
|
83
89
|
createAdminApiClient: () => createAdminApiClient,
|
|
84
90
|
createAdminApiClientFromHttpClient: () => createAdminApiClientFromHttpClient,
|
|
@@ -106,6 +112,7 @@ __export(index_exports, {
|
|
|
106
112
|
createSignedReleaseVerifier: () => createSignedReleaseVerifier,
|
|
107
113
|
createTimeoutSignal: () => createTimeoutSignal,
|
|
108
114
|
createUniversalHttpClient: () => createUniversalHttpClient,
|
|
115
|
+
createdSubgroupId: () => createdSubgroupId,
|
|
109
116
|
creationInitHash: () => creationInitHash,
|
|
110
117
|
defaultAdmitters: () => defaultAdmitters,
|
|
111
118
|
defaultAudience: () => defaultAudience,
|
|
@@ -124,8 +131,10 @@ __export(index_exports, {
|
|
|
124
131
|
generateSessionKey: () => generateSessionKey,
|
|
125
132
|
governanceOpHash: () => governanceOpHash,
|
|
126
133
|
groupCreatedOp: () => groupCreatedOp,
|
|
134
|
+
groupDeleteOp: () => groupDeleteOp,
|
|
127
135
|
groupDeletedOp: () => groupDeletedOp,
|
|
128
136
|
groupInvitationHash: () => groupInvitationHash,
|
|
137
|
+
groupMetadataSetOp: () => groupMetadataSetOp,
|
|
129
138
|
groupReparentedOp: () => groupReparentedOp,
|
|
130
139
|
hasCap: () => hasCap,
|
|
131
140
|
hexEncodeUtf8: () => hexEncodeUtf8,
|
|
@@ -135,13 +144,18 @@ __export(index_exports, {
|
|
|
135
144
|
localNodeUrl: () => localNodeUrl,
|
|
136
145
|
login: () => login,
|
|
137
146
|
memberAddedOp: () => memberAddedOp,
|
|
147
|
+
memberCapabilitySetOp: () => memberCapabilitySetOp,
|
|
148
|
+
memberJoinedOpenOp: () => memberJoinedOpenOp,
|
|
138
149
|
memberLeftOp: () => memberLeftOp,
|
|
150
|
+
memberMetadataSetOp: () => memberMetadataSetOp,
|
|
139
151
|
memberRemovedOp: () => memberRemovedOp,
|
|
140
152
|
memberRoleSetOp: () => memberRoleSetOp,
|
|
141
153
|
mintDeviceId: () => mintDeviceId,
|
|
142
154
|
namespaceCreatedOp: () => namespaceCreatedOp,
|
|
143
155
|
nodeEndpoint: () => nodeEndpoint,
|
|
144
156
|
nodeReleaseVersionFromImage: () => nodeReleaseVersionFromImage,
|
|
157
|
+
ownerOpDigest: () => ownerOpDigest,
|
|
158
|
+
ownerOpSigningPayload: () => ownerOpSigningPayload,
|
|
145
159
|
parseAuthCallback: () => parseAuthCallback,
|
|
146
160
|
parseCreationWarrant: () => parseCreationWarrant,
|
|
147
161
|
parseDeviceCredential: () => parseDeviceCredential,
|
|
@@ -155,6 +169,7 @@ __export(index_exports, {
|
|
|
155
169
|
requestBodyHash: () => requestBodyHash,
|
|
156
170
|
resolveRoot: () => resolveRoot,
|
|
157
171
|
resolveRootPair: () => resolveRootPair,
|
|
172
|
+
rootGuardedOpBytes: () => rootGuardedOpBytes,
|
|
158
173
|
routingProofHeaders: () => routingProofHeaders,
|
|
159
174
|
shouldRetain: () => shouldRetain,
|
|
160
175
|
signAccountLink: () => signAccountLink,
|
|
@@ -166,6 +181,7 @@ __export(index_exports, {
|
|
|
166
181
|
signGroupInvitation: () => signGroupInvitation,
|
|
167
182
|
signLoginStatement: () => signLoginStatement,
|
|
168
183
|
signMemberJoinOp: () => signMemberJoinOp,
|
|
184
|
+
signOwnerOpProof: () => signOwnerOpProof,
|
|
169
185
|
signRequest: () => signRequest,
|
|
170
186
|
signRequestProof: () => signRequestProof,
|
|
171
187
|
signRoutingChallenge: () => signRoutingChallenge,
|
|
@@ -173,6 +189,12 @@ __export(index_exports, {
|
|
|
173
189
|
signedPath: () => signedPath,
|
|
174
190
|
signerFromCryptoKey: () => signerFromCryptoKey,
|
|
175
191
|
signerFromSecret: () => signerFromSecret,
|
|
192
|
+
subgroupCreation: () => subgroupCreation,
|
|
193
|
+
subgroupVisibilitySetOp: () => subgroupVisibilitySetOp,
|
|
194
|
+
teeAdmissionPolicyOp: () => teeAdmissionPolicyOp,
|
|
195
|
+
teeAuthoringPolicyOp: () => teeAuthoringPolicyOp,
|
|
196
|
+
teeReleaseAdmissionPolicyOp: () => teeReleaseAdmissionPolicyOp,
|
|
197
|
+
transferOwnershipOp: () => transferOwnershipOp,
|
|
176
198
|
transportKeyBinding: () => transportKeyBinding,
|
|
177
199
|
trustSignedRelease: () => trustSignedRelease,
|
|
178
200
|
trustedMeasurementsFromReleases: () => trustedMeasurementsFromReleases,
|
|
@@ -2353,9 +2375,45 @@ var AdminApiClient = class {
|
|
|
2353
2375
|
* and admitted TEEs stay members. The node applies the same op as
|
|
2354
2376
|
* `setTeeAuthoringPolicy(groupId, { allowedMrtd: [] })`. `groupId` must be a
|
|
2355
2377
|
* namespace root.
|
|
2378
|
+
*
|
|
2379
|
+
* `rootProof` is the signing admin's own root proof for that empty policy
|
|
2380
|
+
* (`teeAuthoringPolicyOp([])`); omit it on a node that holds that root.
|
|
2381
|
+
*/
|
|
2382
|
+
async disableTeeAuthoringPolicy(groupId, options = {}) {
|
|
2383
|
+
const path = `/admin-api/groups/${groupId}/settings/tee-authoring-policy`;
|
|
2384
|
+
if (options.rootProof === void 0) {
|
|
2385
|
+
await this.httpClient.delete(path);
|
|
2386
|
+
return;
|
|
2387
|
+
}
|
|
2388
|
+
await this.httpClient.request(path, {
|
|
2389
|
+
method: "DELETE",
|
|
2390
|
+
body: JSON.stringify({ rootProof: options.rootProof }),
|
|
2391
|
+
headers: { "Content-Type": "application/json" }
|
|
2392
|
+
});
|
|
2393
|
+
}
|
|
2394
|
+
// ---- Root-guarded owner ops (core schema 18) ----
|
|
2395
|
+
/**
|
|
2396
|
+
* Hand the group to `newOwner`, who must already be one of its admins.
|
|
2397
|
+
* Owner-only, and it needs the owner account's root proof; see
|
|
2398
|
+
* {@link RootGuardedOpRequest}.
|
|
2399
|
+
*/
|
|
2400
|
+
async transferOwnership(groupId, request) {
|
|
2401
|
+
await this.httpClient.post(`/admin-api/groups/${groupId}/transfer-ownership`, request);
|
|
2402
|
+
}
|
|
2403
|
+
/**
|
|
2404
|
+
* Repoint the namespace's admin pin at `newAdmin`, a member of its root.
|
|
2405
|
+
* Owner-only, with the owner account's root proof; see {@link RootGuardedOpRequest}.
|
|
2406
|
+
*/
|
|
2407
|
+
async changeNamespaceAdmin(namespaceId, request) {
|
|
2408
|
+
await this.httpClient.post(`/admin-api/namespaces/${namespaceId}/admin`, request);
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* Delete a group through the owner-only path: it must hold no contexts, and
|
|
2412
|
+
* the op needs the owner account's root proof. {@link deleteGroup} is the
|
|
2413
|
+
* admin-level cascading delete.
|
|
2356
2414
|
*/
|
|
2357
|
-
async
|
|
2358
|
-
await this.httpClient.
|
|
2415
|
+
async ownerDeleteGroup(groupId, request = {}) {
|
|
2416
|
+
await this.httpClient.post(`/admin-api/groups/${groupId}/owner-delete`, request);
|
|
2359
2417
|
}
|
|
2360
2418
|
// ---- Group / member / context metadata ----
|
|
2361
2419
|
async setGroupMetadata(groupId, request) {
|
|
@@ -7349,9 +7407,9 @@ function parseCreationWarrant(warrant) {
|
|
|
7349
7407
|
const u32 = (what) => view.getUint32(take(4, what).byteOffset, true);
|
|
7350
7408
|
const u64 = (what) => view.getBigUint64(take(8, what).byteOffset, true);
|
|
7351
7409
|
const option = (what) => {
|
|
7352
|
-
const
|
|
7353
|
-
if (
|
|
7354
|
-
if (
|
|
7410
|
+
const tag3 = take(1, what)[0];
|
|
7411
|
+
if (tag3 === 0) return null;
|
|
7412
|
+
if (tag3 !== 1) throw new Error(`${what} has option tag ${tag3}, expected 0 or 1`);
|
|
7355
7413
|
const len = u32(what);
|
|
7356
7414
|
if (len > MAX_LABEL_BYTES) {
|
|
7357
7415
|
throw new Error(`${what} is ${len} bytes, over the ${MAX_LABEL_BYTES} a node accepts`);
|
|
@@ -7540,12 +7598,21 @@ var GROUP_OP = {
|
|
|
7540
7598
|
MemberRemoved: 2,
|
|
7541
7599
|
MemberLeft: 3,
|
|
7542
7600
|
MemberRoleSet: 4,
|
|
7543
|
-
|
|
7601
|
+
MemberCapabilitySet: 5,
|
|
7602
|
+
DefaultCapabilitiesSet: 6,
|
|
7603
|
+
ContextDetached: 9,
|
|
7604
|
+
SubgroupVisibilitySet: 10,
|
|
7605
|
+
GroupMetadataSet: 11,
|
|
7606
|
+
MemberMetadataSet: 12,
|
|
7607
|
+
ContextMetadataSet: 13,
|
|
7608
|
+
ContextCapabilityGranted: 16,
|
|
7609
|
+
ContextCapabilityRevoked: 17
|
|
7544
7610
|
};
|
|
7545
7611
|
var ROOT_OP = {
|
|
7546
7612
|
GroupCreated: 0,
|
|
7547
7613
|
GroupReparented: 1,
|
|
7548
7614
|
GroupDeleted: 2,
|
|
7615
|
+
MemberJoinedOpen: 7,
|
|
7549
7616
|
NamespaceCreatedV2: 9
|
|
7550
7617
|
};
|
|
7551
7618
|
var NAMESPACE_ID_DOMAIN = new TextEncoder().encode("calimero.namespace.id.v1");
|
|
@@ -7595,6 +7662,17 @@ function memberRoleSetOp(member, memberRole) {
|
|
|
7595
7662
|
bytes: concat(tag(GROUP_OP.MemberRoleSet), fromHex(member, "member", 32), role(memberRole))
|
|
7596
7663
|
};
|
|
7597
7664
|
}
|
|
7665
|
+
var SUBGROUP_ID_DOMAIN = new TextEncoder().encode("calimero.subgroup.id.v1");
|
|
7666
|
+
async function createdSubgroupId(admin, parentId, restricted, salt) {
|
|
7667
|
+
return hex(
|
|
7668
|
+
await domainHash(SUBGROUP_ID_DOMAIN, [
|
|
7669
|
+
fromHex(admin, "admin", 32),
|
|
7670
|
+
fromHex(parentId, "parentId", 32),
|
|
7671
|
+
new Uint8Array([restricted ? 1 : 0]),
|
|
7672
|
+
fromHex(salt, "salt", 32)
|
|
7673
|
+
])
|
|
7674
|
+
);
|
|
7675
|
+
}
|
|
7598
7676
|
function defaultCapabilitiesSetOp(capabilities) {
|
|
7599
7677
|
if (!Number.isInteger(capabilities) || capabilities < 0 || capabilities > 4294967295) {
|
|
7600
7678
|
throw new Error(`capabilities must be a u32 bit mask, got ${String(capabilities)}`);
|
|
@@ -7617,10 +7695,16 @@ function groupCreatedOp(input) {
|
|
|
7617
7695
|
fromHex(input.groupId, "groupId", 32),
|
|
7618
7696
|
fromHex(input.parentId, "parentId", 32),
|
|
7619
7697
|
tag(input.restricted ? 1 : 0),
|
|
7620
|
-
fromHex(input.admin, "admin", 32)
|
|
7698
|
+
fromHex(input.admin, "admin", 32),
|
|
7699
|
+
fromHex(input.salt, "salt", 32)
|
|
7621
7700
|
)
|
|
7622
7701
|
};
|
|
7623
7702
|
}
|
|
7703
|
+
async function subgroupCreation(input) {
|
|
7704
|
+
const salt = input.salt ?? hex(crypto.getRandomValues(new Uint8Array(32)));
|
|
7705
|
+
const groupId = await createdSubgroupId(input.admin, input.parentId, input.restricted, salt);
|
|
7706
|
+
return { groupId, salt, op: groupCreatedOp({ ...input, groupId, salt }) };
|
|
7707
|
+
}
|
|
7624
7708
|
function groupReparentedOp(childGroupId, newParentId) {
|
|
7625
7709
|
return {
|
|
7626
7710
|
kind: "root",
|
|
@@ -7660,6 +7744,87 @@ function namespaceCreatedOp(input) {
|
|
|
7660
7744
|
)
|
|
7661
7745
|
};
|
|
7662
7746
|
}
|
|
7747
|
+
function str(value) {
|
|
7748
|
+
const bytes = new TextEncoder().encode(value);
|
|
7749
|
+
return concat(u32le(bytes.length), bytes);
|
|
7750
|
+
}
|
|
7751
|
+
function optionalStr(value) {
|
|
7752
|
+
return value === void 0 ? tag(0) : concat(tag(1), str(value));
|
|
7753
|
+
}
|
|
7754
|
+
function stringMap(data = {}) {
|
|
7755
|
+
const enc = new TextEncoder();
|
|
7756
|
+
const entries = Object.entries(data).map(([k, v]) => [enc.encode(k), v, k]).sort(([a], [b]) => {
|
|
7757
|
+
for (let i = 0; i < Math.min(a.length, b.length); i++) if (a[i] !== b[i]) return a[i] - b[i];
|
|
7758
|
+
return a.length - b.length;
|
|
7759
|
+
});
|
|
7760
|
+
return concat(u32le(entries.length), ...entries.flatMap(([, v, k]) => [str(k), str(v)]));
|
|
7761
|
+
}
|
|
7762
|
+
function relayableMask(capabilities, what) {
|
|
7763
|
+
if (!Number.isInteger(capabilities) || capabilities < 0 || capabilities > 4294967295) {
|
|
7764
|
+
throw new Error(`${what} must be a u32 bit mask, got ${String(capabilities)}`);
|
|
7765
|
+
}
|
|
7766
|
+
if (hasCap(capabilities, CAPABILITIES.CAN_AUTHOR_ON_BEHALF)) {
|
|
7767
|
+
throw new Error(`${what} may not include CAN_AUTHOR_ON_BEHALF (512): a relay never carries a change to it`);
|
|
7768
|
+
}
|
|
7769
|
+
return capabilities;
|
|
7770
|
+
}
|
|
7771
|
+
function memberCapabilitySetOp(member, capabilities) {
|
|
7772
|
+
return {
|
|
7773
|
+
kind: "group",
|
|
7774
|
+
bytes: concat(tag(GROUP_OP.MemberCapabilitySet), fromHex(member, "member", 32), u32le(relayableMask(capabilities, "capabilities")))
|
|
7775
|
+
};
|
|
7776
|
+
}
|
|
7777
|
+
function contextDetachedOp(contextId) {
|
|
7778
|
+
return { kind: "group", bytes: concat(tag(GROUP_OP.ContextDetached), fromHex(contextId, "contextId", 32)) };
|
|
7779
|
+
}
|
|
7780
|
+
function subgroupVisibilitySetOp(mode) {
|
|
7781
|
+
if (mode !== "open" && mode !== "restricted") throw new Error(`mode must be open or restricted, got ${String(mode)}`);
|
|
7782
|
+
return { kind: "group", bytes: concat(tag(GROUP_OP.SubgroupVisibilitySet), tag(mode === "open" ? 0 : 1)) };
|
|
7783
|
+
}
|
|
7784
|
+
function groupMetadataSetOp(input = {}) {
|
|
7785
|
+
return { kind: "group", bytes: concat(tag(GROUP_OP.GroupMetadataSet), optionalStr(input.name), stringMap(input.data)) };
|
|
7786
|
+
}
|
|
7787
|
+
function memberMetadataSetOp(member, input = {}) {
|
|
7788
|
+
return {
|
|
7789
|
+
kind: "group",
|
|
7790
|
+
bytes: concat(tag(GROUP_OP.MemberMetadataSet), fromHex(member, "member", 32), optionalStr(input.name), stringMap(input.data))
|
|
7791
|
+
};
|
|
7792
|
+
}
|
|
7793
|
+
function contextMetadataSetOp(contextId, input = {}) {
|
|
7794
|
+
return {
|
|
7795
|
+
kind: "group",
|
|
7796
|
+
bytes: concat(tag(GROUP_OP.ContextMetadataSet), fromHex(contextId, "contextId", 32), optionalStr(input.name), stringMap(input.data))
|
|
7797
|
+
};
|
|
7798
|
+
}
|
|
7799
|
+
function contextCapability(capability) {
|
|
7800
|
+
if (!Number.isInteger(capability) || capability < 1 || capability > 255) {
|
|
7801
|
+
throw new Error(`capability must be a non-zero u8, got ${String(capability)}`);
|
|
7802
|
+
}
|
|
7803
|
+
return tag(capability);
|
|
7804
|
+
}
|
|
7805
|
+
function contextCapabilityGrantedOp(contextId, member, capability) {
|
|
7806
|
+
return {
|
|
7807
|
+
kind: "group",
|
|
7808
|
+
bytes: concat(tag(GROUP_OP.ContextCapabilityGranted), fromHex(contextId, "contextId", 32), fromHex(member, "member", 32), contextCapability(capability))
|
|
7809
|
+
};
|
|
7810
|
+
}
|
|
7811
|
+
function contextCapabilityRevokedOp(contextId, member, capability) {
|
|
7812
|
+
return {
|
|
7813
|
+
kind: "group",
|
|
7814
|
+
bytes: concat(tag(GROUP_OP.ContextCapabilityRevoked), fromHex(contextId, "contextId", 32), fromHex(member, "member", 32), contextCapability(capability))
|
|
7815
|
+
};
|
|
7816
|
+
}
|
|
7817
|
+
function memberJoinedOpenOp(input) {
|
|
7818
|
+
return {
|
|
7819
|
+
kind: "root",
|
|
7820
|
+
bytes: concat(
|
|
7821
|
+
tag(ROOT_OP.MemberJoinedOpen),
|
|
7822
|
+
fromHex(input.member, "member", 32),
|
|
7823
|
+
fromHex(input.groupId, "groupId", 32),
|
|
7824
|
+
fromHexUnsized(input.credential, "credential")
|
|
7825
|
+
)
|
|
7826
|
+
};
|
|
7827
|
+
}
|
|
7663
7828
|
|
|
7664
7829
|
// src/relay/relay-client.ts
|
|
7665
7830
|
var DEFAULT_TTL_SECONDS = 300;
|
|
@@ -8178,12 +8343,12 @@ function audienceSigningBytes(audience) {
|
|
|
8178
8343
|
);
|
|
8179
8344
|
}
|
|
8180
8345
|
function audienceWire(audience) {
|
|
8181
|
-
const
|
|
8346
|
+
const tag3 = Uint8Array.from([AUDIENCE_TAG[audience.kind]]);
|
|
8182
8347
|
if (audience.kind === "cli") {
|
|
8183
|
-
return
|
|
8348
|
+
return tag3;
|
|
8184
8349
|
}
|
|
8185
8350
|
const body = audienceBody(audience);
|
|
8186
|
-
return concat(
|
|
8351
|
+
return concat(tag3, u32le(body.length), body);
|
|
8187
8352
|
}
|
|
8188
8353
|
async function signLoginStatement(input) {
|
|
8189
8354
|
const node = fromHex(input.node, "node", 32);
|
|
@@ -9868,8 +10033,8 @@ var SIGNATURE_HASHES = {
|
|
|
9868
10033
|
};
|
|
9869
10034
|
function read(bytes, offset, limit) {
|
|
9870
10035
|
if (offset + 2 > limit) throw new Error("it is truncated");
|
|
9871
|
-
const
|
|
9872
|
-
if ((
|
|
10036
|
+
const tag3 = bytes[offset];
|
|
10037
|
+
if ((tag3 & 31) === 31) throw new Error("it uses a tag this parser does not read");
|
|
9873
10038
|
let length = bytes[offset + 1];
|
|
9874
10039
|
let start = offset + 2;
|
|
9875
10040
|
if (length & 128) {
|
|
@@ -9881,7 +10046,7 @@ function read(bytes, offset, limit) {
|
|
|
9881
10046
|
}
|
|
9882
10047
|
const end = start + length;
|
|
9883
10048
|
if (end > limit) throw new Error("it is truncated");
|
|
9884
|
-
return { tag:
|
|
10049
|
+
return { tag: tag3, bytes, offset, start, end };
|
|
9885
10050
|
}
|
|
9886
10051
|
function parseDer(bytes) {
|
|
9887
10052
|
const element = read(bytes, 0, bytes.length);
|
|
@@ -9897,8 +10062,8 @@ function children(element) {
|
|
|
9897
10062
|
}
|
|
9898
10063
|
return out;
|
|
9899
10064
|
}
|
|
9900
|
-
function expectTag(element,
|
|
9901
|
-
if (!element || element.tag !==
|
|
10065
|
+
function expectTag(element, tag3, what) {
|
|
10066
|
+
if (!element || element.tag !== tag3) throw new Error(`${what} is not where it should be`);
|
|
9902
10067
|
return element;
|
|
9903
10068
|
}
|
|
9904
10069
|
function contents(element) {
|
|
@@ -10456,7 +10621,7 @@ function bytes32(value, label2) {
|
|
|
10456
10621
|
}
|
|
10457
10622
|
|
|
10458
10623
|
// src/namespace-op/namespace-op.ts
|
|
10459
|
-
var SIGNED_NAMESPACE_OP_SCHEMA_VERSION =
|
|
10624
|
+
var SIGNED_NAMESPACE_OP_SCHEMA_VERSION = 20;
|
|
10460
10625
|
var NAMESPACE_SIGN_DOMAIN = new TextEncoder().encode("calimero.namespace.v1");
|
|
10461
10626
|
var NAMESPACE_OP_ROOT = 0;
|
|
10462
10627
|
var ROOT_OP2 = {
|
|
@@ -10546,6 +10711,183 @@ async function signMemberJoinOp(input) {
|
|
|
10546
10711
|
return hex(concat(signable, signature, unendorsed));
|
|
10547
10712
|
}
|
|
10548
10713
|
|
|
10714
|
+
// src/owner-op/owner-op.ts
|
|
10715
|
+
var OWNER_OP_SIGN_DOMAIN = new TextEncoder().encode("calimero.account.owner-op.v1");
|
|
10716
|
+
var OWNER_OP_BODY_DOMAIN = new TextEncoder().encode("calimero.account.owner-op.body.v1");
|
|
10717
|
+
var ACCOUNT_ID_DOMAIN2 = new TextEncoder().encode("calimero.account.genesis.v1");
|
|
10718
|
+
var ACCOUNT_GENESIS_VERSION2 = 2;
|
|
10719
|
+
var OWNER_OP_KIND = {
|
|
10720
|
+
transferOwnership: 0,
|
|
10721
|
+
adminChanged: 1,
|
|
10722
|
+
groupDelete: 2,
|
|
10723
|
+
teeAdmissionPolicy: 3,
|
|
10724
|
+
teeAuthoringPolicy: 4,
|
|
10725
|
+
teeReleaseAdmissionPolicy: 5
|
|
10726
|
+
};
|
|
10727
|
+
var GROUP_OP2 = {
|
|
10728
|
+
GroupDelete: 14,
|
|
10729
|
+
TransferOwnership: 21,
|
|
10730
|
+
TeeAuthoringPolicySet: 33,
|
|
10731
|
+
TeeAdmissionPolicySetV2: 37,
|
|
10732
|
+
TeeReleaseAdmissionPolicySetV2: 38,
|
|
10733
|
+
RootGuarded: 42
|
|
10734
|
+
};
|
|
10735
|
+
var ROOT_OP3 = {
|
|
10736
|
+
AdminChanged: 3,
|
|
10737
|
+
RootGuarded: 12
|
|
10738
|
+
};
|
|
10739
|
+
var TEE_MODE = { replica: 0, relay: 1 };
|
|
10740
|
+
var te = new TextEncoder();
|
|
10741
|
+
function tag2(byte) {
|
|
10742
|
+
return new Uint8Array([byte]);
|
|
10743
|
+
}
|
|
10744
|
+
function borshString3(value) {
|
|
10745
|
+
const bytes = te.encode(value);
|
|
10746
|
+
return concat(u32le(bytes.length), bytes);
|
|
10747
|
+
}
|
|
10748
|
+
function borshStrings(values) {
|
|
10749
|
+
return concat(u32le(values.length), ...values.map(borshString3));
|
|
10750
|
+
}
|
|
10751
|
+
function borshBool(value) {
|
|
10752
|
+
return tag2(value ? 1 : 0);
|
|
10753
|
+
}
|
|
10754
|
+
function teeMode(mode) {
|
|
10755
|
+
const byte = TEE_MODE[mode ?? "replica"];
|
|
10756
|
+
if (byte === void 0) {
|
|
10757
|
+
throw new Error(`mode must be replica or relay, got ${String(mode)}`);
|
|
10758
|
+
}
|
|
10759
|
+
return tag2(byte);
|
|
10760
|
+
}
|
|
10761
|
+
function transferOwnershipOp(newOwner) {
|
|
10762
|
+
return {
|
|
10763
|
+
kind: "transferOwnership",
|
|
10764
|
+
plane: "group",
|
|
10765
|
+
bytes: concat(tag2(GROUP_OP2.TransferOwnership), fromHex(newOwner, "newOwner", 32))
|
|
10766
|
+
};
|
|
10767
|
+
}
|
|
10768
|
+
function groupDeleteOp() {
|
|
10769
|
+
return { kind: "groupDelete", plane: "group", bytes: tag2(GROUP_OP2.GroupDelete) };
|
|
10770
|
+
}
|
|
10771
|
+
function adminChangedOp(newAdmin) {
|
|
10772
|
+
return {
|
|
10773
|
+
kind: "adminChanged",
|
|
10774
|
+
plane: "root",
|
|
10775
|
+
bytes: concat(tag2(ROOT_OP3.AdminChanged), fromHex(newAdmin, "newAdmin", 32))
|
|
10776
|
+
};
|
|
10777
|
+
}
|
|
10778
|
+
function teeAuthoringPolicyOp(allowedMrtd) {
|
|
10779
|
+
return {
|
|
10780
|
+
kind: "teeAuthoringPolicy",
|
|
10781
|
+
plane: "group",
|
|
10782
|
+
bytes: concat(tag2(GROUP_OP2.TeeAuthoringPolicySet), borshStrings(allowedMrtd))
|
|
10783
|
+
};
|
|
10784
|
+
}
|
|
10785
|
+
function teeAdmissionPolicyOp(input) {
|
|
10786
|
+
return {
|
|
10787
|
+
kind: "teeAdmissionPolicy",
|
|
10788
|
+
plane: "group",
|
|
10789
|
+
bytes: concat(
|
|
10790
|
+
tag2(GROUP_OP2.TeeAdmissionPolicySetV2),
|
|
10791
|
+
borshStrings(input.allowedMrtd),
|
|
10792
|
+
borshStrings(input.allowedRtmr0),
|
|
10793
|
+
borshStrings(input.allowedRtmr1),
|
|
10794
|
+
borshStrings(input.allowedRtmr2),
|
|
10795
|
+
borshStrings(input.allowedRtmr3),
|
|
10796
|
+
borshStrings(input.allowedTcbStatuses),
|
|
10797
|
+
borshBool(input.acceptMock),
|
|
10798
|
+
teeMode(input.mode)
|
|
10799
|
+
)
|
|
10800
|
+
};
|
|
10801
|
+
}
|
|
10802
|
+
function teeReleaseAdmissionPolicyOp(input) {
|
|
10803
|
+
const minRelease = input.minReleaseVersion === void 0 ? tag2(0) : concat(tag2(1), borshString3(input.minReleaseVersion));
|
|
10804
|
+
return {
|
|
10805
|
+
kind: "teeReleaseAdmissionPolicy",
|
|
10806
|
+
plane: "group",
|
|
10807
|
+
bytes: concat(
|
|
10808
|
+
tag2(GROUP_OP2.TeeReleaseAdmissionPolicySetV2),
|
|
10809
|
+
borshStrings(input.allowedProfiles),
|
|
10810
|
+
minRelease,
|
|
10811
|
+
borshStrings(input.allowedTcbStatuses),
|
|
10812
|
+
borshBool(input.acceptMock),
|
|
10813
|
+
teeMode(input.mode)
|
|
10814
|
+
)
|
|
10815
|
+
};
|
|
10816
|
+
}
|
|
10817
|
+
async function ownerOpDigest(opBytes) {
|
|
10818
|
+
return domainHash(OWNER_OP_BODY_DOMAIN, [opBytes]);
|
|
10819
|
+
}
|
|
10820
|
+
async function ownerOpSigningPayload(input) {
|
|
10821
|
+
return domainHash(OWNER_OP_SIGN_DOMAIN, [
|
|
10822
|
+
fromHex(input.account, "account", 32),
|
|
10823
|
+
fromHex(input.namespaceId, "namespaceId", 32),
|
|
10824
|
+
fromHex(input.groupId, "groupId", 32),
|
|
10825
|
+
tag2(kindByte2(input.kind)),
|
|
10826
|
+
input.opDigest,
|
|
10827
|
+
u64le(input.counter),
|
|
10828
|
+
u32le(input.keyEpoch)
|
|
10829
|
+
]);
|
|
10830
|
+
}
|
|
10831
|
+
function kindByte2(kind) {
|
|
10832
|
+
const byte = OWNER_OP_KIND[kind];
|
|
10833
|
+
if (byte === void 0) {
|
|
10834
|
+
throw new Error(`unknown owner-op kind ${String(kind)}`);
|
|
10835
|
+
}
|
|
10836
|
+
return byte;
|
|
10837
|
+
}
|
|
10838
|
+
var HANDOFF_BYTES = 32 + 4 + 32 + 64;
|
|
10839
|
+
async function signOwnerOpProof(input) {
|
|
10840
|
+
const rootPublicKey = await derivePublicKey(input.rootSecret);
|
|
10841
|
+
const genesis = concat(tag2(ACCOUNT_GENESIS_VERSION2), rootPublicKey);
|
|
10842
|
+
const account = hex(await domainHash(ACCOUNT_ID_DOMAIN2, [genesis]));
|
|
10843
|
+
const keyEpoch = input.keyEpoch ?? 0;
|
|
10844
|
+
const chain = (input.chain ?? []).map((handoff, index) => {
|
|
10845
|
+
const bytes = fromHexUnsized(handoff, `chain[${index}]`);
|
|
10846
|
+
if (bytes.length !== HANDOFF_BYTES) {
|
|
10847
|
+
throw new Error(
|
|
10848
|
+
`chain[${index}] must be a ${HANDOFF_BYTES}-byte RootKeyHandoff, got ${bytes.length}`
|
|
10849
|
+
);
|
|
10850
|
+
}
|
|
10851
|
+
return bytes;
|
|
10852
|
+
});
|
|
10853
|
+
if (keyEpoch > chain.length) {
|
|
10854
|
+
throw new Error(
|
|
10855
|
+
`keyEpoch ${keyEpoch} needs ${keyEpoch} handoffs in chain, got ${chain.length}`
|
|
10856
|
+
);
|
|
10857
|
+
}
|
|
10858
|
+
const opDigest = await ownerOpDigest(input.op.bytes);
|
|
10859
|
+
const payload = await ownerOpSigningPayload({
|
|
10860
|
+
account,
|
|
10861
|
+
namespaceId: input.namespaceId,
|
|
10862
|
+
groupId: input.groupId,
|
|
10863
|
+
kind: input.op.kind,
|
|
10864
|
+
opDigest,
|
|
10865
|
+
counter: input.counter,
|
|
10866
|
+
keyEpoch
|
|
10867
|
+
});
|
|
10868
|
+
const key = await importSigningKey(input.rootSecret);
|
|
10869
|
+
const signature = new Uint8Array(await crypto.subtle.sign("Ed25519", key, payload));
|
|
10870
|
+
return hex(
|
|
10871
|
+
concat(
|
|
10872
|
+
genesis,
|
|
10873
|
+
u32le(chain.length),
|
|
10874
|
+
...chain,
|
|
10875
|
+
fromHex(account, "account", 32),
|
|
10876
|
+
fromHex(input.namespaceId, "namespaceId", 32),
|
|
10877
|
+
fromHex(input.groupId, "groupId", 32),
|
|
10878
|
+
tag2(kindByte2(input.op.kind)),
|
|
10879
|
+
opDigest,
|
|
10880
|
+
u64le(input.counter),
|
|
10881
|
+
u32le(keyEpoch),
|
|
10882
|
+
signature
|
|
10883
|
+
)
|
|
10884
|
+
);
|
|
10885
|
+
}
|
|
10886
|
+
function rootGuardedOpBytes(op, rootProof) {
|
|
10887
|
+
const wrapper = op.plane === "group" ? GROUP_OP2.RootGuarded : ROOT_OP3.RootGuarded;
|
|
10888
|
+
return concat(tag2(wrapper), op.bytes, fromHexUnsized(rootProof, "rootProof"));
|
|
10889
|
+
}
|
|
10890
|
+
|
|
10549
10891
|
// src/nodeDiscovery.ts
|
|
10550
10892
|
var DEFAULT_LOCAL_NODE_PORTS = [2428, 2429, 2528, 2529];
|
|
10551
10893
|
var LOCAL_HOST = "localhost";
|