@calimero-network/mero-js 23.1.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/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 +53 -2
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +53 -2
- package/dist/index.mjs.map +4 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -174,6 +174,7 @@ __export(index_exports, {
|
|
|
174
174
|
shouldRetain: () => shouldRetain,
|
|
175
175
|
signAccountLink: () => signAccountLink,
|
|
176
176
|
signAccountLogin: () => signAccountLogin,
|
|
177
|
+
signAccountOwnershipClaim: () => signAccountOwnershipClaim,
|
|
177
178
|
signCreationWarrant: () => signCreationWarrant,
|
|
178
179
|
signDeviceCert: () => signDeviceCert,
|
|
179
180
|
signDeviceScope: () => signDeviceScope,
|
|
@@ -6482,6 +6483,19 @@ var CloudClient = class {
|
|
|
6482
6483
|
{ body }
|
|
6483
6484
|
);
|
|
6484
6485
|
}
|
|
6486
|
+
/**
|
|
6487
|
+
* Enable HA for a namespace this ACCOUNT founded through a relay, with the
|
|
6488
|
+
* founder's claim (`signAccountOwnershipClaim`) instead of a node's
|
|
6489
|
+
* ownership proof: a nodeless account holds no node that could issue one.
|
|
6490
|
+
* The login must be linked to that account.
|
|
6491
|
+
*/
|
|
6492
|
+
async enableFoundedNamespaceHa(namespaceId, ownershipProof) {
|
|
6493
|
+
return this.request(
|
|
6494
|
+
"POST",
|
|
6495
|
+
`/api/cloud/me/namespaces/${encodeURIComponent(namespaceId)}/enable-ha`,
|
|
6496
|
+
{ body: { groups: [], ownership_proof: ownershipProof } }
|
|
6497
|
+
);
|
|
6498
|
+
}
|
|
6485
6499
|
/**
|
|
6486
6500
|
* Stop hosting a claimed namespace.
|
|
6487
6501
|
*
|
|
@@ -9183,8 +9197,8 @@ async function hkdf2(chainingKey, inputKeyMaterial) {
|
|
|
9183
9197
|
return [first, second];
|
|
9184
9198
|
}
|
|
9185
9199
|
function base64UrlDecode(value) {
|
|
9186
|
-
const
|
|
9187
|
-
const binary = atob(
|
|
9200
|
+
const base644 = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
9201
|
+
const binary = atob(base644 + "=".repeat((4 - base644.length % 4) % 4));
|
|
9188
9202
|
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
9189
9203
|
}
|
|
9190
9204
|
|
|
@@ -9840,6 +9854,43 @@ function assertSafeReturnTo(returnTo) {
|
|
|
9840
9854
|
);
|
|
9841
9855
|
}
|
|
9842
9856
|
|
|
9857
|
+
// src/cloud/account-ownership.ts
|
|
9858
|
+
var DOMAIN = new TextEncoder().encode("calimero.mdma.account-ownership-claim.v1\0");
|
|
9859
|
+
var DEFAULT_TTL_MS = 6e4;
|
|
9860
|
+
var MAX_TTL_MS = 5 * 6e4;
|
|
9861
|
+
function base643(bytes) {
|
|
9862
|
+
let binary = "";
|
|
9863
|
+
for (const b of bytes) binary += String.fromCharCode(b);
|
|
9864
|
+
return btoa(binary);
|
|
9865
|
+
}
|
|
9866
|
+
var hex32 = (value, what) => {
|
|
9867
|
+
if (!/^[0-9a-fA-F]{64}$/.test(value)) throw new Error(`${what} must be 64 hex characters`);
|
|
9868
|
+
return value.toLowerCase();
|
|
9869
|
+
};
|
|
9870
|
+
async function signAccountOwnershipClaim(input) {
|
|
9871
|
+
const ttl = input.ttlMs ?? DEFAULT_TTL_MS;
|
|
9872
|
+
if (!(ttl > 0 && ttl <= MAX_TTL_MS)) throw new Error(`ttlMs must be in (0, ${MAX_TTL_MS}]`);
|
|
9873
|
+
if (!input.subject) throw new Error("subject must be the cloud login email");
|
|
9874
|
+
const signer = await resolveSigner(input.deviceSecret, input.signer, "deviceSecret");
|
|
9875
|
+
const issued = (input.now ?? Date.now)();
|
|
9876
|
+
const nonce2 = Array.from(crypto.getRandomValues(new Uint8Array(16)), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
9877
|
+
const payload = new TextEncoder().encode(
|
|
9878
|
+
JSON.stringify({
|
|
9879
|
+
v: 1,
|
|
9880
|
+
audience: "mdma:enable-ha-namespace",
|
|
9881
|
+
group_id: hex32(input.namespaceId, "namespaceId"),
|
|
9882
|
+
account_id: hex32(input.accountId, "accountId"),
|
|
9883
|
+
salt: hex32(input.salt, "salt"),
|
|
9884
|
+
subject: input.subject,
|
|
9885
|
+
nonce: nonce2,
|
|
9886
|
+
issued_at_ms: issued,
|
|
9887
|
+
expires_at_ms: issued + ttl
|
|
9888
|
+
})
|
|
9889
|
+
);
|
|
9890
|
+
const signature = await signer.sign(concat(DOMAIN, payload));
|
|
9891
|
+
return { kind: "account", credential: input.credential, signed_payload: base643(payload), signature: base643(signature) };
|
|
9892
|
+
}
|
|
9893
|
+
|
|
9843
9894
|
// src/sealed/verify.ts
|
|
9844
9895
|
var MEASUREMENT_HEX = /^[0-9a-f]{96}$/;
|
|
9845
9896
|
var REGISTERS = ["mrtd", "rtmr0", "rtmr1", "rtmr2", "rtmr3"];
|