@invisi-labs/sdk 1.1.0 → 1.1.2

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/indexeddb.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TransactionalWalletStore
3
- } from "./chunk-T246CYQ7.js";
4
- import "./chunk-NAEEEZMH.js";
3
+ } from "./chunk-Z6NDXVBL.js";
4
+ import "./chunk-4HMM7ZKY.js";
5
5
 
6
6
  // src/integrations/indexeddb.ts
7
7
  var IndexedDBAtomicRecords = class {
package/dist/memory.cjs CHANGED
@@ -80,6 +80,9 @@ var import_ethers = require("ethers");
80
80
  var import_contracts = require("@invisi-labs/protocol/contracts");
81
81
  var import_address = require("@invisi-labs/core/address");
82
82
  var getAddress = (value) => (0, import_ethers.getAddress)(value);
83
+ var erc1271Abi = [
84
+ "function isValidSignature(bytes32 hash, bytes signature) view returns (bytes4)"
85
+ ];
83
86
  function check(value, message) {
84
87
  if (!value) {
85
88
  throw new Error(message);
@@ -111,6 +114,28 @@ var EthersChainReader = class {
111
114
  async getChainId() {
112
115
  return (await this.client.getNetwork()).chainId;
113
116
  }
117
+ async isValidRegistrationSignature(owner, digest, signature) {
118
+ try {
119
+ const result = await this.client.call({
120
+ to: getAddress(owner),
121
+ data: new import_ethers.Interface(erc1271Abi).encodeFunctionData("isValidSignature", [
122
+ digest,
123
+ signature
124
+ ])
125
+ });
126
+ return result.length >= 66 && result.slice(0, 66).toLowerCase() === "0x1626ba7e" + "00".repeat(28);
127
+ } catch (error) {
128
+ if ((0, import_ethers.isError)(error, "CALL_EXCEPTION")) return false;
129
+ throw error;
130
+ }
131
+ }
132
+ async getProtocolAddressRegistry(address2) {
133
+ return getAddress(
134
+ await new import_ethers.Contract(getAddress(address2), import_contracts.invisiProtocolAbi, this.client).getFunction(
135
+ "addressRegistry"
136
+ )()
137
+ );
138
+ }
114
139
  async getProtocolVersion(address2) {
115
140
  return BigInt(
116
141
  await new import_ethers.Contract(getAddress(address2), import_contracts.invisiProtocolAbi, this.client).getFunction(
@@ -491,25 +516,27 @@ function extractDeliveryCandidates(logs, context, confirmedThrough) {
491
516
  const tokens = array(a.tokens);
492
517
  const cs = array(a.commitments), tree = integer(a.treeId), start = index(a.startLeafIndex), packed = a.packedDeliveries;
493
518
  check2(
494
- typeof packed === "string" && /^0x(?:[0-9a-fA-F]{2})*$/.test(packed) && packed.length === 2 + 452 * cs.length,
519
+ typeof packed === "string" && /^0x(?:[0-9a-fA-F]{2})*$/.test(packed),
495
520
  "invalid packed deliveries"
496
521
  );
497
522
  check2(tokens.length === cs.length, "batch token count mismatch");
523
+ check2(start + cs.length <= 65536, "batch exceeds tree capacity");
524
+ let offset = 2;
498
525
  cs.forEach((c, i) => {
499
- const segment = packed.slice(2 + 452 * i, 2 + 452 * (i + 1));
500
- add(
501
- log,
502
- tree,
503
- start + i,
504
- c,
505
- "funds",
506
- {
507
- ciphertext: `0x${segment.slice(0, 316)}`,
508
- clue: `0x${segment.slice(316)}`
509
- },
510
- tokens[i]
526
+ check2(offset + 4 <= packed.length, "truncated delivery length prefix");
527
+ const length = Number.parseInt(packed.slice(offset, offset + 4), 16);
528
+ offset += 4;
529
+ check2(
530
+ length >= 160 && length <= 416 && offset + length * 2 + 136 <= packed.length,
531
+ "invalid packed delivery length"
511
532
  );
533
+ const ciphertext = `0x${packed.slice(offset, offset + length * 2)}`;
534
+ offset += length * 2;
535
+ const clue = `0x${packed.slice(offset, offset + 136)}`;
536
+ offset += 136;
537
+ add(log, tree, start + i, c, "funds", { ciphertext, clue }, tokens[i]);
512
538
  });
539
+ check2(offset === packed.length, "trailing packed delivery bytes");
513
540
  } else if (log.eventName === "CreditCreated") creation(log, a, a);
514
541
  else if (log.eventName === "CreditToppedUp")
515
542
  creation(log, a, object(object(a.params).creation));
@@ -3121,6 +3148,7 @@ var Preparation = class {
3121
3148
  const recipient = await import_core8.ReceivingAddress.parse(payment.to).resolve(
3122
3149
  this.runtime.options.addressResolver
3123
3150
  );
3151
+ const memo = (0, import_core8.encodeMemo)(payment.memo);
3124
3152
  const nonce = (0, import_core8.generateNonce)();
3125
3153
  const identity = await (0, import_core8.computeNoteIdentity)(BigInt(recipient.walletIdentity), nonce);
3126
3154
  const keys = recipient.getReceivingKeys();
@@ -3130,6 +3158,7 @@ var Preparation = class {
3130
3158
  tokenAddress: BigInt(context.tokenAddress),
3131
3159
  walletIdentity: recipient.walletIdentity,
3132
3160
  amount: payment.amount,
3161
+ ...memo.length === 0 ? {} : { memo },
3133
3162
  nonce
3134
3163
  };
3135
3164
  const commitment = await (0, import_core8.computeNoteCommitment)(
@@ -3365,6 +3394,7 @@ var CreditPreparation = class {
3365
3394
  ownerPayout: BigInt(ownerPayout),
3366
3395
  spenderPayout: BigInt(spenderPayout),
3367
3396
  amount: options.amount,
3397
+ ...options.memo === void 0 ? {} : { memo: options.memo },
3368
3398
  expiry,
3369
3399
  nonce: (0, import_core9.generateNonce)(),
3370
3400
  creditSharedKey: (0, import_core9.generateCreditSharedKey)()
@@ -3456,7 +3486,16 @@ var CreditPreparation = class {
3456
3486
  }
3457
3487
  const amount = positiveAmount(old.note.amount + options.additionalAmount, 126);
3458
3488
  const output = await this.seal(
3459
- { ...old, note: { ...old.note, amount, expiry, nonce: (0, import_core9.generateNonce)() } },
3489
+ {
3490
+ ...old,
3491
+ note: {
3492
+ ...old.note,
3493
+ amount,
3494
+ expiry,
3495
+ nonce: (0, import_core9.generateNonce)(),
3496
+ ...options.memo === void 0 ? {} : { memo: options.memo }
3497
+ }
3498
+ },
3460
3499
  frame
3461
3500
  );
3462
3501
  return this.creation(
@@ -3522,6 +3561,7 @@ var CreditPreparation = class {
3522
3561
  note: {
3523
3562
  ...n,
3524
3563
  amount: remaining,
3564
+ ...options.credits[i].memo === void 0 ? {} : { memo: options.credits[i].memo },
3525
3565
  nonce: await (0, import_core9.deriveRemainderNonce)(...args)
3526
3566
  }
3527
3567
  },
@@ -3991,6 +4031,10 @@ var InventoryProcessor = class {
3991
4031
  if (!remainder) {
3992
4032
  continue;
3993
4033
  }
4034
+ const child = foundByKey.get(
4035
+ params.remainderCommitments[index2] + ":" + previous.role
4036
+ );
4037
+ const memo = child?.state.note.memo;
3994
4038
  const record = {
3995
4039
  commitment: params.remainderCommitments[index2],
3996
4040
  treeId: BigInt(args.outputTreeId),
@@ -3999,7 +4043,13 @@ var InventoryProcessor = class {
3999
4043
  blockHash: event.blockHash,
4000
4044
  transactionHash: event.transactionHash,
4001
4045
  role: previous.role,
4002
- state: { ...clone(previous.state), note: remainder },
4046
+ state: {
4047
+ ...clone(previous.state),
4048
+ note: {
4049
+ ...remainder,
4050
+ ...memo === void 0 ? {} : { memo: (0, import_core10.encodeMemo)(memo) }
4051
+ }
4052
+ },
4003
4053
  receivingKeySource: { kind: "draw", commitment: previous.commitment },
4004
4054
  spent: "unknown"
4005
4055
  };