@calimero-network/mero-js 19.14.1 → 19.15.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
@@ -77,12 +77,14 @@ __export(index_exports, {
77
77
  nodeEndpoint: () => nodeEndpoint,
78
78
  parseAuthCallback: () => parseAuthCallback,
79
79
  probeNodeHealth: () => probeNodeHealth,
80
+ requestBodyHash: () => requestBodyHash,
80
81
  routingProofHeaders: () => routingProofHeaders,
81
82
  signAccountLink: () => signAccountLink,
82
83
  signAccountLogin: () => signAccountLogin,
83
84
  signDeviceCert: () => signDeviceCert,
84
85
  signLoginStatement: () => signLoginStatement,
85
86
  signMemberJoinOp: () => signMemberJoinOp,
87
+ signRequest: () => signRequest,
86
88
  signRoutingChallenge: () => signRoutingChallenge,
87
89
  signWarrant: () => signWarrant,
88
90
  withCap: () => withCap,
@@ -6535,8 +6537,47 @@ async function signMemberJoinOp(input) {
6535
6537
  return hex(concat(signable, signature, unendorsed));
6536
6538
  }
6537
6539
 
6540
+ // src/request/request-sig.ts
6541
+ var SIGN_DOMAIN2 = new TextEncoder().encode("calimero.auth.request.v1");
6542
+ var BODY_DOMAIN = new TextEncoder().encode("calimero.auth.request.body.v1");
6543
+ function borshString2(value) {
6544
+ const bytes = new TextEncoder().encode(value);
6545
+ return concat(u32le(bytes.length), bytes);
6546
+ }
6547
+ async function requestBodyHash(body = new Uint8Array(0)) {
6548
+ const bytes = typeof body === "string" ? new TextEncoder().encode(body) : body;
6549
+ return domainHash(BODY_DOMAIN, [bytes]);
6550
+ }
6551
+ async function signRequest(input) {
6552
+ const key = await importSigningKey(input.signerSecret);
6553
+ const bodyHash = await requestBodyHash(input.body);
6554
+ const issuedAt = u64le(input.issuedAt);
6555
+ const expiresAt = u64le(input.expiresAt);
6556
+ const encoder = new TextEncoder();
6557
+ const preimage = await domainHash(SIGN_DOMAIN2, [
6558
+ encoder.encode(input.method),
6559
+ encoder.encode(input.path),
6560
+ bodyHash,
6561
+ issuedAt,
6562
+ expiresAt
6563
+ ]);
6564
+ const signature = new Uint8Array(
6565
+ await crypto.subtle.sign({ name: "Ed25519" }, key, preimage)
6566
+ );
6567
+ return hex(
6568
+ concat(
6569
+ borshString2(input.method),
6570
+ borshString2(input.path),
6571
+ bodyHash,
6572
+ issuedAt,
6573
+ expiresAt,
6574
+ signature
6575
+ )
6576
+ );
6577
+ }
6578
+
6538
6579
  // src/login/login.ts
6539
- var SIGN_DOMAIN2 = new TextEncoder().encode("calimero.auth.login.v1");
6580
+ var SIGN_DOMAIN3 = new TextEncoder().encode("calimero.auth.login.v1");
6540
6581
  var AUDIENCE_TAG = {
6541
6582
  webOrigin: 0,
6542
6583
  codeSigningId: 1,
@@ -6575,7 +6616,7 @@ async function signLoginStatement(input) {
6575
6616
  const deviceKey = await derivePublicKey(input.deviceSecret);
6576
6617
  const issuedAt = u64le(input.issuedAt);
6577
6618
  const expiresAt = u64le(input.expiresAt);
6578
- const preimage = await domainHash(SIGN_DOMAIN2, [
6619
+ const preimage = await domainHash(SIGN_DOMAIN3, [
6579
6620
  node,
6580
6621
  audienceSigningBytes(input.audience),
6581
6622
  challenge,