@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.cjs CHANGED
@@ -72,6 +72,7 @@ __export(index_exports, {
72
72
  parseAuthCallback: () => parseAuthCallback,
73
73
  probeNodeHealth: () => probeNodeHealth,
74
74
  signDeviceCert: () => signDeviceCert,
75
+ signLoginStatement: () => signLoginStatement,
75
76
  signMemberJoinOp: () => signMemberJoinOp,
76
77
  signWarrant: () => signWarrant,
77
78
  withCap: () => withCap,
@@ -3690,6 +3691,72 @@ async function signMemberJoinOp(input) {
3690
3691
  return hex(concat(signable, signature, unendorsed));
3691
3692
  }
3692
3693
 
3694
+ // src/login/login.ts
3695
+ var SIGN_DOMAIN2 = new TextEncoder().encode("calimero.auth.login.v1");
3696
+ var AUDIENCE_TAG = {
3697
+ webOrigin: 0,
3698
+ codeSigningId: 1,
3699
+ cli: 2
3700
+ };
3701
+ function audienceBody(audience) {
3702
+ const encoder = new TextEncoder();
3703
+ switch (audience.kind) {
3704
+ case "webOrigin":
3705
+ return encoder.encode(audience.origin);
3706
+ case "codeSigningId":
3707
+ return encoder.encode(audience.id);
3708
+ case "cli":
3709
+ return new Uint8Array(0);
3710
+ }
3711
+ }
3712
+ function audienceSigningBytes(audience) {
3713
+ return concat(
3714
+ Uint8Array.from([AUDIENCE_TAG[audience.kind]]),
3715
+ audienceBody(audience)
3716
+ );
3717
+ }
3718
+ function audienceWire(audience) {
3719
+ const tag = Uint8Array.from([AUDIENCE_TAG[audience.kind]]);
3720
+ if (audience.kind === "cli") {
3721
+ return tag;
3722
+ }
3723
+ const body = audienceBody(audience);
3724
+ return concat(tag, u32le(body.length), body);
3725
+ }
3726
+ async function signLoginStatement(input) {
3727
+ const node = fromHex(input.node, "node", 32);
3728
+ const challenge = fromHex(input.challenge, "challenge", 32);
3729
+ const sessionKey = fromHex(input.sessionKey, "sessionKey", 32);
3730
+ const key = await importSigningKey(input.deviceSecret);
3731
+ const deviceKey = await derivePublicKey(input.deviceSecret);
3732
+ const issuedAt = u64le(input.issuedAt);
3733
+ const expiresAt = u64le(input.expiresAt);
3734
+ const preimage = await domainHash(SIGN_DOMAIN2, [
3735
+ node,
3736
+ audienceSigningBytes(input.audience),
3737
+ challenge,
3738
+ sessionKey,
3739
+ deviceKey,
3740
+ issuedAt,
3741
+ expiresAt
3742
+ ]);
3743
+ const signature = new Uint8Array(
3744
+ await crypto.subtle.sign({ name: "Ed25519" }, key, preimage)
3745
+ );
3746
+ return hex(
3747
+ concat(
3748
+ node,
3749
+ audienceWire(input.audience),
3750
+ challenge,
3751
+ sessionKey,
3752
+ deviceKey,
3753
+ issuedAt,
3754
+ expiresAt,
3755
+ signature
3756
+ )
3757
+ );
3758
+ }
3759
+
3693
3760
  // src/capabilities.ts
3694
3761
  var CAPABILITIES = {
3695
3762
  CAN_CREATE_CONTEXT: 1 << 0,