@calimero-network/mero-js 18.3.0 → 19.0.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
@@ -3164,8 +3164,10 @@ async function derivePublicKey(secretHex) {
3164
3164
  }
3165
3165
 
3166
3166
  // src/warrant/warrant.ts
3167
- var SIGN_DOMAIN = new TextEncoder().encode("calimero.warrant.v1");
3167
+ var SIGN_DOMAIN = new TextEncoder().encode("calimero.warrant.v2");
3168
3168
  var INTENT_DOMAIN = new TextEncoder().encode("calimero.warrant.intent.v1");
3169
+ var MAX_CITED_HEADS = 64;
3170
+ var UNPINNED_APP = "00".repeat(32);
3169
3171
  async function intentHash(method, argsJson) {
3170
3172
  const args = new TextEncoder().encode(JSON.stringify(argsJson));
3171
3173
  return domainHash(INTENT_DOMAIN, [new TextEncoder().encode(method), args]);
@@ -3174,8 +3176,16 @@ async function signWarrant(input) {
3174
3176
  const context = fromHex(input.context, "context", 32);
3175
3177
  const authorAccount = fromHex(input.authorAccount, "authorAccount", 32);
3176
3178
  const executor = fromHex(input.executor, "executor", 32);
3179
+ const appVersion = fromHex(
3180
+ input.appVersion ?? UNPINNED_APP,
3181
+ "appVersion",
3182
+ 32
3183
+ );
3184
+ const accountHeads = citedHeads(input.accountHeads, "accountHeads");
3185
+ const governanceFloor = citedHeads(input.governanceFloor, "governanceFloor");
3177
3186
  const key = await importSigningKey(input.deviceSecret);
3178
3187
  const publicKey = await derivePublicKey(input.deviceSecret);
3188
+ const method = new TextEncoder().encode(input.method);
3179
3189
  const commitment = await intentHash(input.method, input.argsJson);
3180
3190
  const nonce = u64le(input.nonce);
3181
3191
  const notAfter = u64le(input.notAfter);
@@ -3184,7 +3194,13 @@ async function signWarrant(input) {
3184
3194
  authorAccount,
3185
3195
  publicKey,
3186
3196
  executor,
3197
+ appVersion,
3198
+ method,
3187
3199
  commitment,
3200
+ u64le(accountHeads.length),
3201
+ ...accountHeads,
3202
+ u64le(governanceFloor.length),
3203
+ ...governanceFloor,
3188
3204
  nonce,
3189
3205
  notAfter
3190
3206
  ]);
@@ -3197,13 +3213,29 @@ async function signWarrant(input) {
3197
3213
  authorAccount,
3198
3214
  publicKey,
3199
3215
  executor,
3216
+ appVersion,
3217
+ u32le(method.length),
3218
+ method,
3200
3219
  commitment,
3220
+ u32le(accountHeads.length),
3221
+ ...accountHeads,
3222
+ u32le(governanceFloor.length),
3223
+ ...governanceFloor,
3201
3224
  nonce,
3202
3225
  notAfter,
3203
3226
  signature
3204
3227
  )
3205
3228
  );
3206
3229
  }
3230
+ function citedHeads(heads, label) {
3231
+ const list = heads ?? [];
3232
+ if (list.length > MAX_CITED_HEADS) {
3233
+ throw new Error(
3234
+ `${label} cites ${list.length} heads, over the ${MAX_CITED_HEADS} a node accepts`
3235
+ );
3236
+ }
3237
+ return list.map((head, i) => fromHex(head, `${label}[${i}]`, 32));
3238
+ }
3207
3239
 
3208
3240
  // src/relay/relay-client.ts
3209
3241
  var DEFAULT_TTL_SECONDS = 300;