@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/memory.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  MemoryAtomicRecords,
3
3
  MemoryWalletStore
4
- } from "./chunk-T246CYQ7.js";
5
- import "./chunk-NAEEEZMH.js";
4
+ } from "./chunk-Z6NDXVBL.js";
5
+ import "./chunk-4HMM7ZKY.js";
6
6
  export {
7
7
  MemoryAtomicRecords,
8
8
  MemoryWalletStore
package/dist/sqlite.cjs CHANGED
@@ -30,6 +30,9 @@ var import_ethers = require("ethers");
30
30
  var import_contracts = require("@invisi-labs/protocol/contracts");
31
31
  var import_address = require("@invisi-labs/core/address");
32
32
  var getAddress = (value) => (0, import_ethers.getAddress)(value);
33
+ var erc1271Abi = [
34
+ "function isValidSignature(bytes32 hash, bytes signature) view returns (bytes4)"
35
+ ];
33
36
  function check(value, message) {
34
37
  if (!value) {
35
38
  throw new Error(message);
@@ -61,6 +64,28 @@ var EthersChainReader = class {
61
64
  async getChainId() {
62
65
  return (await this.client.getNetwork()).chainId;
63
66
  }
67
+ async isValidRegistrationSignature(owner, digest, signature) {
68
+ try {
69
+ const result = await this.client.call({
70
+ to: getAddress(owner),
71
+ data: new import_ethers.Interface(erc1271Abi).encodeFunctionData("isValidSignature", [
72
+ digest,
73
+ signature
74
+ ])
75
+ });
76
+ return result.length >= 66 && result.slice(0, 66).toLowerCase() === "0x1626ba7e" + "00".repeat(28);
77
+ } catch (error) {
78
+ if ((0, import_ethers.isError)(error, "CALL_EXCEPTION")) return false;
79
+ throw error;
80
+ }
81
+ }
82
+ async getProtocolAddressRegistry(address2) {
83
+ return getAddress(
84
+ await new import_ethers.Contract(getAddress(address2), import_contracts.invisiProtocolAbi, this.client).getFunction(
85
+ "addressRegistry"
86
+ )()
87
+ );
88
+ }
64
89
  async getProtocolVersion(address2) {
65
90
  return BigInt(
66
91
  await new import_ethers.Contract(getAddress(address2), import_contracts.invisiProtocolAbi, this.client).getFunction(
@@ -441,25 +466,27 @@ function extractDeliveryCandidates(logs, context, confirmedThrough) {
441
466
  const tokens = array(a.tokens);
442
467
  const cs = array(a.commitments), tree = integer(a.treeId), start = index(a.startLeafIndex), packed = a.packedDeliveries;
443
468
  check2(
444
- typeof packed === "string" && /^0x(?:[0-9a-fA-F]{2})*$/.test(packed) && packed.length === 2 + 452 * cs.length,
469
+ typeof packed === "string" && /^0x(?:[0-9a-fA-F]{2})*$/.test(packed),
445
470
  "invalid packed deliveries"
446
471
  );
447
472
  check2(tokens.length === cs.length, "batch token count mismatch");
473
+ check2(start + cs.length <= 65536, "batch exceeds tree capacity");
474
+ let offset = 2;
448
475
  cs.forEach((c, i) => {
449
- const segment = packed.slice(2 + 452 * i, 2 + 452 * (i + 1));
450
- add(
451
- log,
452
- tree,
453
- start + i,
454
- c,
455
- "funds",
456
- {
457
- ciphertext: `0x${segment.slice(0, 316)}`,
458
- clue: `0x${segment.slice(316)}`
459
- },
460
- tokens[i]
476
+ check2(offset + 4 <= packed.length, "truncated delivery length prefix");
477
+ const length = Number.parseInt(packed.slice(offset, offset + 4), 16);
478
+ offset += 4;
479
+ check2(
480
+ length >= 160 && length <= 416 && offset + length * 2 + 136 <= packed.length,
481
+ "invalid packed delivery length"
461
482
  );
483
+ const ciphertext = `0x${packed.slice(offset, offset + length * 2)}`;
484
+ offset += length * 2;
485
+ const clue = `0x${packed.slice(offset, offset + 136)}`;
486
+ offset += 136;
487
+ add(log, tree, start + i, c, "funds", { ciphertext, clue }, tokens[i]);
462
488
  });
489
+ check2(offset === packed.length, "trailing packed delivery bytes");
463
490
  } else if (log.eventName === "CreditCreated") creation(log, a, a);
464
491
  else if (log.eventName === "CreditToppedUp")
465
492
  creation(log, a, object(object(a.params).creation));
@@ -3059,6 +3086,7 @@ var Preparation = class {
3059
3086
  const recipient = await import_core8.ReceivingAddress.parse(payment.to).resolve(
3060
3087
  this.runtime.options.addressResolver
3061
3088
  );
3089
+ const memo = (0, import_core8.encodeMemo)(payment.memo);
3062
3090
  const nonce = (0, import_core8.generateNonce)();
3063
3091
  const identity = await (0, import_core8.computeNoteIdentity)(BigInt(recipient.walletIdentity), nonce);
3064
3092
  const keys = recipient.getReceivingKeys();
@@ -3068,6 +3096,7 @@ var Preparation = class {
3068
3096
  tokenAddress: BigInt(context.tokenAddress),
3069
3097
  walletIdentity: recipient.walletIdentity,
3070
3098
  amount: payment.amount,
3099
+ ...memo.length === 0 ? {} : { memo },
3071
3100
  nonce
3072
3101
  };
3073
3102
  const commitment = await (0, import_core8.computeNoteCommitment)(
@@ -3303,6 +3332,7 @@ var CreditPreparation = class {
3303
3332
  ownerPayout: BigInt(ownerPayout),
3304
3333
  spenderPayout: BigInt(spenderPayout),
3305
3334
  amount: options.amount,
3335
+ ...options.memo === void 0 ? {} : { memo: options.memo },
3306
3336
  expiry,
3307
3337
  nonce: (0, import_core9.generateNonce)(),
3308
3338
  creditSharedKey: (0, import_core9.generateCreditSharedKey)()
@@ -3394,7 +3424,16 @@ var CreditPreparation = class {
3394
3424
  }
3395
3425
  const amount = positiveAmount(old.note.amount + options.additionalAmount, 126);
3396
3426
  const output = await this.seal(
3397
- { ...old, note: { ...old.note, amount, expiry, nonce: (0, import_core9.generateNonce)() } },
3427
+ {
3428
+ ...old,
3429
+ note: {
3430
+ ...old.note,
3431
+ amount,
3432
+ expiry,
3433
+ nonce: (0, import_core9.generateNonce)(),
3434
+ ...options.memo === void 0 ? {} : { memo: options.memo }
3435
+ }
3436
+ },
3398
3437
  frame
3399
3438
  );
3400
3439
  return this.creation(
@@ -3460,6 +3499,7 @@ var CreditPreparation = class {
3460
3499
  note: {
3461
3500
  ...n,
3462
3501
  amount: remaining,
3502
+ ...options.credits[i].memo === void 0 ? {} : { memo: options.credits[i].memo },
3463
3503
  nonce: await (0, import_core9.deriveRemainderNonce)(...args)
3464
3504
  }
3465
3505
  },
@@ -3929,6 +3969,10 @@ var InventoryProcessor = class {
3929
3969
  if (!remainder) {
3930
3970
  continue;
3931
3971
  }
3972
+ const child = foundByKey.get(
3973
+ params.remainderCommitments[index2] + ":" + previous.role
3974
+ );
3975
+ const memo = child?.state.note.memo;
3932
3976
  const record = {
3933
3977
  commitment: params.remainderCommitments[index2],
3934
3978
  treeId: BigInt(args.outputTreeId),
@@ -3937,7 +3981,13 @@ var InventoryProcessor = class {
3937
3981
  blockHash: event.blockHash,
3938
3982
  transactionHash: event.transactionHash,
3939
3983
  role: previous.role,
3940
- state: { ...clone(previous.state), note: remainder },
3984
+ state: {
3985
+ ...clone(previous.state),
3986
+ note: {
3987
+ ...remainder,
3988
+ ...memo === void 0 ? {} : { memo: (0, import_core10.encodeMemo)(memo) }
3989
+ }
3990
+ },
3941
3991
  receivingKeySource: { kind: "draw", commitment: previous.commitment },
3942
3992
  spent: "unknown"
3943
3993
  };