@calimero-network/mero-js 23.0.0 → 23.2.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-types.d.ts +3 -1
- package/dist/cloud/account-ownership.d.ts +30 -0
- package/dist/cloud/account-ownership.js +55 -0
- package/dist/cloud/cloud-client.d.ts +8 -0
- package/dist/cloud/cloud-client.js +9 -0
- package/dist/cloud/index.d.ts +2 -0
- package/dist/cloud/index.js +1 -0
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +153 -3
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +153 -3
- package/dist/index.mjs.map +4 -4
- package/dist/warrant/governance-op.d.ts +36 -0
- package/dist/warrant/governance-op.js +115 -0
- package/dist/warrant/index.d.ts +1 -1
- package/dist/warrant/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export * from "./cloud/index.js";
|
|
|
21
21
|
export * from "./sealed/index.js";
|
|
22
22
|
export * from "./relay/index.js";
|
|
23
23
|
export * from "./request-proof/index.js";
|
|
24
|
-
export { signWarrant, intentHash, signCreationWarrant, parseCreationWarrant, creationInitHash, signGovernanceWarrant, parseGovernanceWarrant, governanceOpHash, memberAddedOp, memberRemovedOp, memberLeftOp, memberRoleSetOp, groupCreatedOp, createdSubgroupId, subgroupCreation, groupReparentedOp, groupDeletedOp, namespaceCreatedOp, defaultCapabilitiesSetOp, foundedNamespaceId, } from "./warrant/index.js";
|
|
24
|
+
export { signWarrant, intentHash, signCreationWarrant, parseCreationWarrant, creationInitHash, signGovernanceWarrant, parseGovernanceWarrant, governanceOpHash, memberAddedOp, memberRemovedOp, memberLeftOp, memberRoleSetOp, groupCreatedOp, createdSubgroupId, subgroupCreation, groupReparentedOp, groupDeletedOp, memberCapabilitySetOp, contextDetachedOp, subgroupVisibilitySetOp, groupMetadataSetOp, memberMetadataSetOp, contextMetadataSetOp, contextCapabilityGrantedOp, contextCapabilityRevokedOp, memberJoinedOpenOp, namespaceCreatedOp, defaultCapabilitiesSetOp, foundedNamespaceId, } from "./warrant/index.js";
|
|
25
25
|
export { signerFromSecret, signerFromCryptoKey } from "./signer/index.js";
|
|
26
26
|
export type { Signer } from "./signer/index.js";
|
|
27
27
|
export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, createAccountRootSigner, accountRootSignerFromPhrase, signAccountLink, signAccountLogin, resolveRoot, resolveRootPair, } from "./account/index.js";
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ export * from "./relay/index.js";
|
|
|
34
34
|
// Request proofs — a caller's identity on the request itself, no session needed
|
|
35
35
|
export * from "./request-proof/index.js";
|
|
36
36
|
// Warrant signing — mint the author's consent for a relay to run one intent
|
|
37
|
-
export { signWarrant, intentHash, signCreationWarrant, parseCreationWarrant, creationInitHash, signGovernanceWarrant, parseGovernanceWarrant, governanceOpHash, memberAddedOp, memberRemovedOp, memberLeftOp, memberRoleSetOp, groupCreatedOp, createdSubgroupId, subgroupCreation, groupReparentedOp, groupDeletedOp, namespaceCreatedOp, defaultCapabilitiesSetOp, foundedNamespaceId, } from "./warrant/index.js";
|
|
37
|
+
export { signWarrant, intentHash, signCreationWarrant, parseCreationWarrant, creationInitHash, signGovernanceWarrant, parseGovernanceWarrant, governanceOpHash, memberAddedOp, memberRemovedOp, memberLeftOp, memberRoleSetOp, groupCreatedOp, createdSubgroupId, subgroupCreation, groupReparentedOp, groupDeletedOp, memberCapabilitySetOp, contextDetachedOp, subgroupVisibilitySetOp, groupMetadataSetOp, memberMetadataSetOp, contextMetadataSetOp, contextCapabilityGrantedOp, contextCapabilityRevokedOp, memberJoinedOpenOp, namespaceCreatedOp, defaultCapabilitiesSetOp, foundedNamespaceId, } from "./warrant/index.js";
|
|
38
38
|
// Who signs — a key's capability, separated from its material, so a
|
|
39
39
|
// non-extractable key can be used wherever a hex secret could.
|
|
40
40
|
export { signerFromSecret, signerFromCryptoKey } from "./signer/index.js";
|
package/dist/index.mjs
CHANGED
|
@@ -6274,6 +6274,19 @@ var CloudClient = class {
|
|
|
6274
6274
|
{ body }
|
|
6275
6275
|
);
|
|
6276
6276
|
}
|
|
6277
|
+
/**
|
|
6278
|
+
* Enable HA for a namespace this ACCOUNT founded through a relay, with the
|
|
6279
|
+
* founder's claim (`signAccountOwnershipClaim`) instead of a node's
|
|
6280
|
+
* ownership proof: a nodeless account holds no node that could issue one.
|
|
6281
|
+
* The login must be linked to that account.
|
|
6282
|
+
*/
|
|
6283
|
+
async enableFoundedNamespaceHa(namespaceId, ownershipProof) {
|
|
6284
|
+
return this.request(
|
|
6285
|
+
"POST",
|
|
6286
|
+
`/api/cloud/me/namespaces/${encodeURIComponent(namespaceId)}/enable-ha`,
|
|
6287
|
+
{ body: { groups: [], ownership_proof: ownershipProof } }
|
|
6288
|
+
);
|
|
6289
|
+
}
|
|
6277
6290
|
/**
|
|
6278
6291
|
* Stop hosting a claimed namespace.
|
|
6279
6292
|
*
|
|
@@ -7390,12 +7403,21 @@ var GROUP_OP = {
|
|
|
7390
7403
|
MemberRemoved: 2,
|
|
7391
7404
|
MemberLeft: 3,
|
|
7392
7405
|
MemberRoleSet: 4,
|
|
7393
|
-
|
|
7406
|
+
MemberCapabilitySet: 5,
|
|
7407
|
+
DefaultCapabilitiesSet: 6,
|
|
7408
|
+
ContextDetached: 9,
|
|
7409
|
+
SubgroupVisibilitySet: 10,
|
|
7410
|
+
GroupMetadataSet: 11,
|
|
7411
|
+
MemberMetadataSet: 12,
|
|
7412
|
+
ContextMetadataSet: 13,
|
|
7413
|
+
ContextCapabilityGranted: 16,
|
|
7414
|
+
ContextCapabilityRevoked: 17
|
|
7394
7415
|
};
|
|
7395
7416
|
var ROOT_OP = {
|
|
7396
7417
|
GroupCreated: 0,
|
|
7397
7418
|
GroupReparented: 1,
|
|
7398
7419
|
GroupDeleted: 2,
|
|
7420
|
+
MemberJoinedOpen: 7,
|
|
7399
7421
|
NamespaceCreatedV2: 9
|
|
7400
7422
|
};
|
|
7401
7423
|
var NAMESPACE_ID_DOMAIN = new TextEncoder().encode("calimero.namespace.id.v1");
|
|
@@ -7527,6 +7549,87 @@ function namespaceCreatedOp(input) {
|
|
|
7527
7549
|
)
|
|
7528
7550
|
};
|
|
7529
7551
|
}
|
|
7552
|
+
function str(value) {
|
|
7553
|
+
const bytes = new TextEncoder().encode(value);
|
|
7554
|
+
return concat(u32le(bytes.length), bytes);
|
|
7555
|
+
}
|
|
7556
|
+
function optionalStr(value) {
|
|
7557
|
+
return value === void 0 ? tag(0) : concat(tag(1), str(value));
|
|
7558
|
+
}
|
|
7559
|
+
function stringMap(data = {}) {
|
|
7560
|
+
const enc = new TextEncoder();
|
|
7561
|
+
const entries = Object.entries(data).map(([k, v]) => [enc.encode(k), v, k]).sort(([a], [b]) => {
|
|
7562
|
+
for (let i = 0; i < Math.min(a.length, b.length); i++) if (a[i] !== b[i]) return a[i] - b[i];
|
|
7563
|
+
return a.length - b.length;
|
|
7564
|
+
});
|
|
7565
|
+
return concat(u32le(entries.length), ...entries.flatMap(([, v, k]) => [str(k), str(v)]));
|
|
7566
|
+
}
|
|
7567
|
+
function relayableMask(capabilities, what) {
|
|
7568
|
+
if (!Number.isInteger(capabilities) || capabilities < 0 || capabilities > 4294967295) {
|
|
7569
|
+
throw new Error(`${what} must be a u32 bit mask, got ${String(capabilities)}`);
|
|
7570
|
+
}
|
|
7571
|
+
if (hasCap(capabilities, CAPABILITIES.CAN_AUTHOR_ON_BEHALF)) {
|
|
7572
|
+
throw new Error(`${what} may not include CAN_AUTHOR_ON_BEHALF (512): a relay never carries a change to it`);
|
|
7573
|
+
}
|
|
7574
|
+
return capabilities;
|
|
7575
|
+
}
|
|
7576
|
+
function memberCapabilitySetOp(member, capabilities) {
|
|
7577
|
+
return {
|
|
7578
|
+
kind: "group",
|
|
7579
|
+
bytes: concat(tag(GROUP_OP.MemberCapabilitySet), fromHex(member, "member", 32), u32le(relayableMask(capabilities, "capabilities")))
|
|
7580
|
+
};
|
|
7581
|
+
}
|
|
7582
|
+
function contextDetachedOp(contextId) {
|
|
7583
|
+
return { kind: "group", bytes: concat(tag(GROUP_OP.ContextDetached), fromHex(contextId, "contextId", 32)) };
|
|
7584
|
+
}
|
|
7585
|
+
function subgroupVisibilitySetOp(mode) {
|
|
7586
|
+
if (mode !== "open" && mode !== "restricted") throw new Error(`mode must be open or restricted, got ${String(mode)}`);
|
|
7587
|
+
return { kind: "group", bytes: concat(tag(GROUP_OP.SubgroupVisibilitySet), tag(mode === "open" ? 0 : 1)) };
|
|
7588
|
+
}
|
|
7589
|
+
function groupMetadataSetOp(input = {}) {
|
|
7590
|
+
return { kind: "group", bytes: concat(tag(GROUP_OP.GroupMetadataSet), optionalStr(input.name), stringMap(input.data)) };
|
|
7591
|
+
}
|
|
7592
|
+
function memberMetadataSetOp(member, input = {}) {
|
|
7593
|
+
return {
|
|
7594
|
+
kind: "group",
|
|
7595
|
+
bytes: concat(tag(GROUP_OP.MemberMetadataSet), fromHex(member, "member", 32), optionalStr(input.name), stringMap(input.data))
|
|
7596
|
+
};
|
|
7597
|
+
}
|
|
7598
|
+
function contextMetadataSetOp(contextId, input = {}) {
|
|
7599
|
+
return {
|
|
7600
|
+
kind: "group",
|
|
7601
|
+
bytes: concat(tag(GROUP_OP.ContextMetadataSet), fromHex(contextId, "contextId", 32), optionalStr(input.name), stringMap(input.data))
|
|
7602
|
+
};
|
|
7603
|
+
}
|
|
7604
|
+
function contextCapability(capability) {
|
|
7605
|
+
if (!Number.isInteger(capability) || capability < 1 || capability > 255) {
|
|
7606
|
+
throw new Error(`capability must be a non-zero u8, got ${String(capability)}`);
|
|
7607
|
+
}
|
|
7608
|
+
return tag(capability);
|
|
7609
|
+
}
|
|
7610
|
+
function contextCapabilityGrantedOp(contextId, member, capability) {
|
|
7611
|
+
return {
|
|
7612
|
+
kind: "group",
|
|
7613
|
+
bytes: concat(tag(GROUP_OP.ContextCapabilityGranted), fromHex(contextId, "contextId", 32), fromHex(member, "member", 32), contextCapability(capability))
|
|
7614
|
+
};
|
|
7615
|
+
}
|
|
7616
|
+
function contextCapabilityRevokedOp(contextId, member, capability) {
|
|
7617
|
+
return {
|
|
7618
|
+
kind: "group",
|
|
7619
|
+
bytes: concat(tag(GROUP_OP.ContextCapabilityRevoked), fromHex(contextId, "contextId", 32), fromHex(member, "member", 32), contextCapability(capability))
|
|
7620
|
+
};
|
|
7621
|
+
}
|
|
7622
|
+
function memberJoinedOpenOp(input) {
|
|
7623
|
+
return {
|
|
7624
|
+
kind: "root",
|
|
7625
|
+
bytes: concat(
|
|
7626
|
+
tag(ROOT_OP.MemberJoinedOpen),
|
|
7627
|
+
fromHex(input.member, "member", 32),
|
|
7628
|
+
fromHex(input.groupId, "groupId", 32),
|
|
7629
|
+
fromHexUnsized(input.credential, "credential")
|
|
7630
|
+
)
|
|
7631
|
+
};
|
|
7632
|
+
}
|
|
7530
7633
|
|
|
7531
7634
|
// src/relay/relay-client.ts
|
|
7532
7635
|
var DEFAULT_TTL_SECONDS = 300;
|
|
@@ -8885,8 +8988,8 @@ async function hkdf2(chainingKey, inputKeyMaterial) {
|
|
|
8885
8988
|
return [first, second];
|
|
8886
8989
|
}
|
|
8887
8990
|
function base64UrlDecode(value) {
|
|
8888
|
-
const
|
|
8889
|
-
const binary = atob(
|
|
8991
|
+
const base644 = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
8992
|
+
const binary = atob(base644 + "=".repeat((4 - base644.length % 4) % 4));
|
|
8890
8993
|
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
8891
8994
|
}
|
|
8892
8995
|
|
|
@@ -9542,6 +9645,43 @@ function assertSafeReturnTo(returnTo) {
|
|
|
9542
9645
|
);
|
|
9543
9646
|
}
|
|
9544
9647
|
|
|
9648
|
+
// src/cloud/account-ownership.ts
|
|
9649
|
+
var DOMAIN = new TextEncoder().encode("calimero.mdma.account-ownership-claim.v1\0");
|
|
9650
|
+
var DEFAULT_TTL_MS = 6e4;
|
|
9651
|
+
var MAX_TTL_MS = 5 * 6e4;
|
|
9652
|
+
function base643(bytes) {
|
|
9653
|
+
let binary = "";
|
|
9654
|
+
for (const b of bytes) binary += String.fromCharCode(b);
|
|
9655
|
+
return btoa(binary);
|
|
9656
|
+
}
|
|
9657
|
+
var hex32 = (value, what) => {
|
|
9658
|
+
if (!/^[0-9a-fA-F]{64}$/.test(value)) throw new Error(`${what} must be 64 hex characters`);
|
|
9659
|
+
return value.toLowerCase();
|
|
9660
|
+
};
|
|
9661
|
+
async function signAccountOwnershipClaim(input) {
|
|
9662
|
+
const ttl = input.ttlMs ?? DEFAULT_TTL_MS;
|
|
9663
|
+
if (!(ttl > 0 && ttl <= MAX_TTL_MS)) throw new Error(`ttlMs must be in (0, ${MAX_TTL_MS}]`);
|
|
9664
|
+
if (!input.subject) throw new Error("subject must be the cloud login email");
|
|
9665
|
+
const signer = await resolveSigner(input.deviceSecret, input.signer, "deviceSecret");
|
|
9666
|
+
const issued = (input.now ?? Date.now)();
|
|
9667
|
+
const nonce2 = Array.from(crypto.getRandomValues(new Uint8Array(16)), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
9668
|
+
const payload = new TextEncoder().encode(
|
|
9669
|
+
JSON.stringify({
|
|
9670
|
+
v: 1,
|
|
9671
|
+
audience: "mdma:enable-ha-namespace",
|
|
9672
|
+
group_id: hex32(input.namespaceId, "namespaceId"),
|
|
9673
|
+
account_id: hex32(input.accountId, "accountId"),
|
|
9674
|
+
salt: hex32(input.salt, "salt"),
|
|
9675
|
+
subject: input.subject,
|
|
9676
|
+
nonce: nonce2,
|
|
9677
|
+
issued_at_ms: issued,
|
|
9678
|
+
expires_at_ms: issued + ttl
|
|
9679
|
+
})
|
|
9680
|
+
);
|
|
9681
|
+
const signature = await signer.sign(concat(DOMAIN, payload));
|
|
9682
|
+
return { kind: "account", credential: input.credential, signed_payload: base643(payload), signature: base643(signature) };
|
|
9683
|
+
}
|
|
9684
|
+
|
|
9545
9685
|
// src/sealed/verify.ts
|
|
9546
9686
|
var MEASUREMENT_HEX = /^[0-9a-f]{96}$/;
|
|
9547
9687
|
var REGISTERS = ["mrtd", "rtmr0", "rtmr1", "rtmr2", "rtmr3"];
|
|
@@ -10801,6 +10941,10 @@ export {
|
|
|
10801
10941
|
completeDeviceEnrolment,
|
|
10802
10942
|
connectCloud,
|
|
10803
10943
|
connectCloudWithAccount,
|
|
10944
|
+
contextCapabilityGrantedOp,
|
|
10945
|
+
contextCapabilityRevokedOp,
|
|
10946
|
+
contextDetachedOp,
|
|
10947
|
+
contextMetadataSetOp,
|
|
10804
10948
|
createAccountRootSigner,
|
|
10805
10949
|
createAdminApiClient,
|
|
10806
10950
|
createAdminApiClientFromHttpClient,
|
|
@@ -10850,6 +10994,7 @@ export {
|
|
|
10850
10994
|
groupDeleteOp,
|
|
10851
10995
|
groupDeletedOp,
|
|
10852
10996
|
groupInvitationHash,
|
|
10997
|
+
groupMetadataSetOp,
|
|
10853
10998
|
groupReparentedOp,
|
|
10854
10999
|
hasCap,
|
|
10855
11000
|
hexEncodeUtf8,
|
|
@@ -10859,7 +11004,10 @@ export {
|
|
|
10859
11004
|
localNodeUrl,
|
|
10860
11005
|
login,
|
|
10861
11006
|
memberAddedOp,
|
|
11007
|
+
memberCapabilitySetOp,
|
|
11008
|
+
memberJoinedOpenOp,
|
|
10862
11009
|
memberLeftOp,
|
|
11010
|
+
memberMetadataSetOp,
|
|
10863
11011
|
memberRemovedOp,
|
|
10864
11012
|
memberRoleSetOp,
|
|
10865
11013
|
mintDeviceId,
|
|
@@ -10886,6 +11034,7 @@ export {
|
|
|
10886
11034
|
shouldRetain,
|
|
10887
11035
|
signAccountLink,
|
|
10888
11036
|
signAccountLogin,
|
|
11037
|
+
signAccountOwnershipClaim,
|
|
10889
11038
|
signCreationWarrant,
|
|
10890
11039
|
signDeviceCert,
|
|
10891
11040
|
signDeviceScope,
|
|
@@ -10902,6 +11051,7 @@ export {
|
|
|
10902
11051
|
signerFromCryptoKey,
|
|
10903
11052
|
signerFromSecret,
|
|
10904
11053
|
subgroupCreation,
|
|
11054
|
+
subgroupVisibilitySetOp,
|
|
10905
11055
|
teeAdmissionPolicyOp,
|
|
10906
11056
|
teeAuthoringPolicyOp,
|
|
10907
11057
|
teeReleaseAdmissionPolicyOp,
|