@invisi-labs/primitives 1.3.2 → 1.3.4

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.d.cts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ReceivingAddress } from './address.cjs';
2
2
  export { DecodedAddress, ReceivingKeyLookup, decodeAddress } from './address.cjs';
3
- import { N as NoteBytes, a as NoteDecryptionContext, C as CreditStateDecryptionContext } from './encryption-P2HJ89FQ.cjs';
4
- export { b as CreditStateEncryptionContext, c as NoteEncryptionContext, d as decryptCreditState, e as decryptPrivateTransferNote, f as encryptCreditState, g as encryptPrivateTransferNote } from './encryption-P2HJ89FQ.cjs';
5
- import { a as CreditState, b as CreditPolicy, c as CreditUsage, N as Note, P as ProtocolContext, C as CreditDeliveryState, d as CreditDataV1, F as FundsDataV1, R as ReceivingKeys } from './types-CEAuh35C.cjs';
6
- export { e as CreditStateRecovery, M as MAX_MEMO_BYTES, f as Memo, g as decodeMemoText, h as encodeMemo } from './types-CEAuh35C.cjs';
3
+ import { N as NoteBytes, a as NoteDecryptionContext, C as CreditStateDecryptionContext } from './encryption-D6kqiJBR.cjs';
4
+ export { b as CreditStateEncryptionContext, c as NoteEncryptionContext, d as decryptCreditState, e as decryptPrivateTransferNote, f as encryptCreditState, g as encryptPrivateTransferNote } from './encryption-D6kqiJBR.cjs';
5
+ import { a as CreditState, b as CreditPolicy, c as CreditUsage, N as Note, P as ProtocolContext, C as CreditDeliveryState, d as CreditDataV1, F as FundsDataV1, R as ReceivingKeys } from './types-Dqpsk_nc.cjs';
6
+ export { e as CreditStateRecovery, M as MAX_MEMO_BYTES, f as Memo, g as decodeMemoText, h as encodeMemo } from './types-Dqpsk_nc.cjs';
7
7
  export { computeNoteCommitment, computeNoteIdentity, computeNoteNullifier } from './note.cjs';
8
- export { CREDIT_POLICY_FIELDS, CREDIT_USAGE_FIELDS, CreditUpdateChanges, applyCreditDrawUsage, computeCreditCommitment, computeCreditNullifier, computeCreditRecoveryPad, computeCreditSharedKeyHash, creditPeriods, deriveCreditState, deriveCreditStateNonce, deriveCreditUpdate, normalizeCreditDeliveryState, normalizeCreditPolicy, normalizeCreditState, normalizeCreditUsage, recoverCreditState } from './credit.cjs';
8
+ export { CREDIT_POLICY_FIELDS, CREDIT_USAGE_FIELDS, CreditUpdateChanges, applyCreditDrawUsage, computeCreditCommitment, computeCreditNullifier, computeCreditRecoveryPad, computeCreditSharedKeyHash, creditPeriods, deriveCreditState, deriveCreditStateNonce, deriveCreditUpdate, generateCreditGrantId, normalizeCreditDeliveryState, normalizeCreditGrantId, normalizeCreditPolicy, normalizeCreditState, normalizeCreditUsage, recoverCreditState } from './credit.cjs';
9
9
  import { TypedDataField, TypedDataDomain, BytesLike } from 'ethers';
10
10
 
11
11
  /** Compressed secp256k1 viewing key (33 bytes), independent of spending authority. */
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ReceivingAddress } from './address.js';
2
2
  export { DecodedAddress, ReceivingKeyLookup, decodeAddress } from './address.js';
3
- import { N as NoteBytes, a as NoteDecryptionContext, C as CreditStateDecryptionContext } from './encryption-Bzsl9VQk.js';
4
- export { b as CreditStateEncryptionContext, c as NoteEncryptionContext, d as decryptCreditState, e as decryptPrivateTransferNote, f as encryptCreditState, g as encryptPrivateTransferNote } from './encryption-Bzsl9VQk.js';
5
- import { a as CreditState, b as CreditPolicy, c as CreditUsage, N as Note, P as ProtocolContext, C as CreditDeliveryState, d as CreditDataV1, F as FundsDataV1, R as ReceivingKeys } from './types-CEAuh35C.js';
6
- export { e as CreditStateRecovery, M as MAX_MEMO_BYTES, f as Memo, g as decodeMemoText, h as encodeMemo } from './types-CEAuh35C.js';
3
+ import { N as NoteBytes, a as NoteDecryptionContext, C as CreditStateDecryptionContext } from './encryption-HiaDLfia.js';
4
+ export { b as CreditStateEncryptionContext, c as NoteEncryptionContext, d as decryptCreditState, e as decryptPrivateTransferNote, f as encryptCreditState, g as encryptPrivateTransferNote } from './encryption-HiaDLfia.js';
5
+ import { a as CreditState, b as CreditPolicy, c as CreditUsage, N as Note, P as ProtocolContext, C as CreditDeliveryState, d as CreditDataV1, F as FundsDataV1, R as ReceivingKeys } from './types-Dqpsk_nc.js';
6
+ export { e as CreditStateRecovery, M as MAX_MEMO_BYTES, f as Memo, g as decodeMemoText, h as encodeMemo } from './types-Dqpsk_nc.js';
7
7
  export { computeNoteCommitment, computeNoteIdentity, computeNoteNullifier } from './note.js';
8
- export { CREDIT_POLICY_FIELDS, CREDIT_USAGE_FIELDS, CreditUpdateChanges, applyCreditDrawUsage, computeCreditCommitment, computeCreditNullifier, computeCreditRecoveryPad, computeCreditSharedKeyHash, creditPeriods, deriveCreditState, deriveCreditStateNonce, deriveCreditUpdate, normalizeCreditDeliveryState, normalizeCreditPolicy, normalizeCreditState, normalizeCreditUsage, recoverCreditState } from './credit.js';
8
+ export { CREDIT_POLICY_FIELDS, CREDIT_USAGE_FIELDS, CreditUpdateChanges, applyCreditDrawUsage, computeCreditCommitment, computeCreditNullifier, computeCreditRecoveryPad, computeCreditSharedKeyHash, creditPeriods, deriveCreditState, deriveCreditStateNonce, deriveCreditUpdate, generateCreditGrantId, normalizeCreditDeliveryState, normalizeCreditGrantId, normalizeCreditPolicy, normalizeCreditState, normalizeCreditUsage, recoverCreditState } from './credit.js';
9
9
  import { TypedDataField, TypedDataDomain, BytesLike } from 'ethers';
10
10
 
11
11
  /** Compressed secp256k1 viewing key (33 bytes), independent of spending authority. */
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  computeNoteNullifier
3
- } from "./chunk-QLGXGUSB.js";
3
+ } from "./chunk-PNJ3LCJE.js";
4
4
  import {
5
5
  CREDIT_POLICY_FIELDS,
6
6
  CREDIT_USAGE_FIELDS,
@@ -38,9 +38,11 @@ import {
38
38
  encryptCreditState,
39
39
  encryptPrivateTransferNote,
40
40
  exportPayloadKey,
41
+ generateCreditGrantId,
41
42
  generateCreditSharedKey,
42
43
  generateNonce,
43
44
  normalizeCreditDeliveryState,
45
+ normalizeCreditGrantId,
44
46
  normalizeCreditPolicy,
45
47
  normalizeCreditState,
46
48
  normalizeCreditUsage,
@@ -50,7 +52,7 @@ import {
50
52
  validateContext,
51
53
  validateDeliveryCiphertext,
52
54
  viewingPublicKey
53
- } from "./chunk-JRPMFP3G.js";
55
+ } from "./chunk-JQJPQGFX.js";
54
56
  import {
55
57
  MissingCapabilityError,
56
58
  ReceivingAddress,
@@ -70,8 +72,7 @@ var NOTE_FIELDS = ["ownerAddress", "amount", "nonce"];
70
72
  var CREDIT_FIELDS = [
71
73
  "spenderWalletIdentity",
72
74
  "ownerWalletIdentity",
73
- "revocationShard",
74
- "revocationSlot",
75
+ "grantId",
75
76
  "nonce",
76
77
  "expiry",
77
78
  "creditSharedKeyHash",
@@ -144,8 +145,7 @@ async function creditOpening(note) {
144
145
  unlimited: copied.unlimited,
145
146
  spenderWalletIdentity: owner(copied.spenderWalletIdentity, "spender identity"),
146
147
  ownerWalletIdentity: owner(copied.ownerWalletIdentity, "owner identity"),
147
- revocationShard: number(copied.revocationShard, 64, "revocation shard"),
148
- revocationSlot: number(copied.revocationSlot, 16, "revocation slot"),
148
+ grantId: normalizeCreditGrantId(copied.grantId),
149
149
  nonce: nonce(copied.nonce),
150
150
  expiry: number(copied.expiry, 64, "expiry"),
151
151
  creditSharedKeyHash: await computeCreditSharedKeyHash(copied.creditSharedKey)
@@ -293,7 +293,7 @@ var Disclosure = class _Disclosure {
293
293
  throw Error("invalid disclosure unlimited");
294
294
  data[key] = raw[key];
295
295
  } else {
296
- const bits = key === "availableCredit" ? 128 : key.endsWith("Payout") ? 160 : key === "expiry" ? 64 : key === "amount" ? root.kind === "note" ? 128 : 126 : 254;
296
+ const bits = key === "availableCredit" || key === "grantId" ? 128 : key.endsWith("Payout") ? 160 : key === "expiry" ? 64 : key === "amount" ? root.kind === "note" ? 128 : 126 : 254;
297
297
  const parsed = decimal(raw[key], bits, key);
298
298
  if (key === "nonce") nonce(parsed);
299
299
  data[key] = parsed.toString();
@@ -400,8 +400,7 @@ var Disclosure = class _Disclosure {
400
400
  ...scoped,
401
401
  spenderWalletIdentity: data.spenderWalletIdentity,
402
402
  ownerWalletIdentity: data.ownerWalletIdentity,
403
- revocationShard: BigInt(data.revocationShard),
404
- revocationSlot: BigInt(data.revocationSlot),
403
+ grantId: normalizeCreditGrantId(data.grantId),
405
404
  nonce: BigInt(data.nonce),
406
405
  expiry: BigInt(data.expiry),
407
406
  ...normalizeCreditPolicy(
@@ -513,6 +512,19 @@ function walletAuthorizationTypedData(request) {
513
512
  for (const value of words)
514
513
  if (typeof value !== "bigint" || value < 0n || value >= FIELD_MODULUS)
515
514
  throw new RangeError("noncanonical public field");
515
+ if (operation !== "transact") {
516
+ const expected = operation === "create-credit" ? 11 : operation === "update-credit" ? 14 : operation === "credit-draw" ? 15 + 9 * capacity : 15;
517
+ if (words.length !== expected) throw new Error("invalid Credit statement width");
518
+ const start = operation === "update-credit" ? 8 : operation === "credit-draw" ? 6 + 5 * capacity : 4;
519
+ const count = operation === "credit-draw" ? capacity : 1;
520
+ const actual = operation === "credit-draw" ? Number(words[3]) : 1;
521
+ if (!Number.isSafeInteger(actual) || actual <= 0 || actual > count)
522
+ throw new Error("invalid grant count");
523
+ for (let i = 0; i < count; i++) {
524
+ if (i < actual) normalizeCreditGrantId(words[start + i]);
525
+ else if (words[start + i] !== 0n) throw new Error("grantId padding must be zero");
526
+ }
527
+ }
516
528
  const { chainId, protocolAddress } = context2;
517
529
  if (typeof chainId !== "bigint" || chainId < 0n || chainId >= 1n << 64n)
518
530
  throw new RangeError("invalid chain id");
@@ -539,7 +551,7 @@ function walletAuthorizationTypedData(request) {
539
551
  operation: hex(
540
552
  keccak_256(
541
553
  utf8ToBytes(
542
- `Invisi.${OPERATIONS[operation]}.${operation === "transact" ? "v1" : "v4"}`
554
+ `Invisi.${OPERATIONS[operation]}.${operation === "transact" ? "v1" : "GrantId.Uint128.v1"}`
543
555
  )
544
556
  )
545
557
  ),
@@ -1331,9 +1343,11 @@ export {
1331
1343
  encryptCreditState,
1332
1344
  encryptPrivateTransferNote,
1333
1345
  fundsV1,
1346
+ generateCreditGrantId,
1334
1347
  generateCreditSharedKey,
1335
1348
  generateNonce,
1336
1349
  normalizeCreditDeliveryState,
1350
+ normalizeCreditGrantId,
1337
1351
  normalizeCreditPolicy,
1338
1352
  normalizeCreditState,
1339
1353
  normalizeCreditUsage,