@calimero-network/mero-js 19.2.0 → 19.3.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/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +67 -0
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +67 -0
- package/dist/index.mjs.map +4 -4
- package/dist/login/index.d.ts +2 -0
- package/dist/login/index.js +2 -0
- package/dist/login/login.d.ts +101 -0
- package/dist/login/login.js +109 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export type { DeviceCertInput } from './device-cert/index.js';
|
|
|
22
22
|
export { signMemberJoinOp, encodeSignedInvitation, SIGNED_NAMESPACE_OP_SCHEMA_VERSION, } from './namespace-op/index.js';
|
|
23
23
|
export type { SignMemberJoinInput } from './namespace-op/index.js';
|
|
24
24
|
export type { WarrantInput } from './warrant/index.js';
|
|
25
|
+
export { signLoginStatement } from './login/index.js';
|
|
26
|
+
export type { Audience, LoginStatementInput } from './login/index.js';
|
|
25
27
|
export * from './capabilities.js';
|
|
26
28
|
export { DEFAULT_LOCAL_NODE_PORTS, localNodeUrl, nodeEndpoint, probeNodeHealth, discoverLocalNodes, } from './nodeDiscovery.js';
|
|
27
29
|
export type { DiscoverLocalNodesOptions } from './nodeDiscovery.js';
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,8 @@ export * from './relay/index.js';
|
|
|
26
26
|
export { signWarrant, intentHash } from './warrant/index.js';
|
|
27
27
|
export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, } from './device-cert/index.js';
|
|
28
28
|
export { signMemberJoinOp, encodeSignedInvitation, SIGNED_NAMESPACE_OP_SCHEMA_VERSION, } from './namespace-op/index.js';
|
|
29
|
+
// Login-statement signing — the device's half of a password-free session
|
|
30
|
+
export { signLoginStatement } from './login/index.js';
|
|
29
31
|
// Member capability bitmask constants & helpers
|
|
30
32
|
export * from './capabilities.js';
|
|
31
33
|
// Utilities
|
package/dist/index.mjs
CHANGED
|
@@ -3608,6 +3608,72 @@ async function signMemberJoinOp(input) {
|
|
|
3608
3608
|
return hex(concat(signable, signature, unendorsed));
|
|
3609
3609
|
}
|
|
3610
3610
|
|
|
3611
|
+
// src/login/login.ts
|
|
3612
|
+
var SIGN_DOMAIN2 = new TextEncoder().encode("calimero.auth.login.v1");
|
|
3613
|
+
var AUDIENCE_TAG = {
|
|
3614
|
+
webOrigin: 0,
|
|
3615
|
+
codeSigningId: 1,
|
|
3616
|
+
cli: 2
|
|
3617
|
+
};
|
|
3618
|
+
function audienceBody(audience) {
|
|
3619
|
+
const encoder = new TextEncoder();
|
|
3620
|
+
switch (audience.kind) {
|
|
3621
|
+
case "webOrigin":
|
|
3622
|
+
return encoder.encode(audience.origin);
|
|
3623
|
+
case "codeSigningId":
|
|
3624
|
+
return encoder.encode(audience.id);
|
|
3625
|
+
case "cli":
|
|
3626
|
+
return new Uint8Array(0);
|
|
3627
|
+
}
|
|
3628
|
+
}
|
|
3629
|
+
function audienceSigningBytes(audience) {
|
|
3630
|
+
return concat(
|
|
3631
|
+
Uint8Array.from([AUDIENCE_TAG[audience.kind]]),
|
|
3632
|
+
audienceBody(audience)
|
|
3633
|
+
);
|
|
3634
|
+
}
|
|
3635
|
+
function audienceWire(audience) {
|
|
3636
|
+
const tag = Uint8Array.from([AUDIENCE_TAG[audience.kind]]);
|
|
3637
|
+
if (audience.kind === "cli") {
|
|
3638
|
+
return tag;
|
|
3639
|
+
}
|
|
3640
|
+
const body = audienceBody(audience);
|
|
3641
|
+
return concat(tag, u32le(body.length), body);
|
|
3642
|
+
}
|
|
3643
|
+
async function signLoginStatement(input) {
|
|
3644
|
+
const node = fromHex(input.node, "node", 32);
|
|
3645
|
+
const challenge = fromHex(input.challenge, "challenge", 32);
|
|
3646
|
+
const sessionKey = fromHex(input.sessionKey, "sessionKey", 32);
|
|
3647
|
+
const key = await importSigningKey(input.deviceSecret);
|
|
3648
|
+
const deviceKey = await derivePublicKey(input.deviceSecret);
|
|
3649
|
+
const issuedAt = u64le(input.issuedAt);
|
|
3650
|
+
const expiresAt = u64le(input.expiresAt);
|
|
3651
|
+
const preimage = await domainHash(SIGN_DOMAIN2, [
|
|
3652
|
+
node,
|
|
3653
|
+
audienceSigningBytes(input.audience),
|
|
3654
|
+
challenge,
|
|
3655
|
+
sessionKey,
|
|
3656
|
+
deviceKey,
|
|
3657
|
+
issuedAt,
|
|
3658
|
+
expiresAt
|
|
3659
|
+
]);
|
|
3660
|
+
const signature = new Uint8Array(
|
|
3661
|
+
await crypto.subtle.sign({ name: "Ed25519" }, key, preimage)
|
|
3662
|
+
);
|
|
3663
|
+
return hex(
|
|
3664
|
+
concat(
|
|
3665
|
+
node,
|
|
3666
|
+
audienceWire(input.audience),
|
|
3667
|
+
challenge,
|
|
3668
|
+
sessionKey,
|
|
3669
|
+
deviceKey,
|
|
3670
|
+
issuedAt,
|
|
3671
|
+
expiresAt,
|
|
3672
|
+
signature
|
|
3673
|
+
)
|
|
3674
|
+
);
|
|
3675
|
+
}
|
|
3676
|
+
|
|
3611
3677
|
// src/capabilities.ts
|
|
3612
3678
|
var CAPABILITIES = {
|
|
3613
3679
|
CAN_CREATE_CONTEXT: 1 << 0,
|
|
@@ -3749,6 +3815,7 @@ export {
|
|
|
3749
3815
|
parseAuthCallback,
|
|
3750
3816
|
probeNodeHealth,
|
|
3751
3817
|
signDeviceCert,
|
|
3818
|
+
signLoginStatement,
|
|
3752
3819
|
signMemberJoinOp,
|
|
3753
3820
|
signWarrant,
|
|
3754
3821
|
withCap,
|