From afe53f1bbd68a570324dd6f422b606e15edb4838 Mon Sep 17 00:00:00 2001 From: ardier16 Date: Wed, 20 Mar 2024 14:18:45 +0200 Subject: [PATCH] Restructurize connector --- .../connector/abis/LightweightStateV2.json | 564 +++++++++++ packages/connector/abis/StateV2.json | 945 ++++++++++++++++++ packages/connector/package.json | 5 +- packages/connector/src/consts/general.ts | 1 - packages/connector/src/consts/index.ts | 1 + packages/connector/src/consts/snap.ts | 1 + packages/connector/src/contracts/index.ts | 8 - packages/connector/src/enums/index.ts | 1 + packages/connector/src/enums/snap.ts | 11 + packages/connector/src/helpers/index.ts | 4 +- .../{promise.helpers.ts => promise.ts} | 0 .../src/{utils.ts => helpers/snap.ts} | 59 +- .../connector/src/helpers/state-v2-helpers.ts | 113 --- packages/connector/src/index.ts | 36 +- packages/connector/src/instances/index.ts | 1 + packages/connector/src/instances/snap.ts | 83 ++ packages/connector/src/methods.ts | 148 --- packages/connector/src/snap.ts | 34 - packages/connector/src/types/index.ts | 1 + packages/connector/src/types/snap.ts | 49 + packages/connector/src/zkp/consts/general.ts | 1 + packages/connector/src/zkp/consts/index.ts | 1 + packages/connector/src/zkp/enums/general.ts | 10 + packages/connector/src/zkp/enums/index.ts | 1 + packages/connector/src/zkp/helpers/index.ts | 1 + .../src/zkp/helpers/state-v2-helpers.ts | 207 ++++ packages/connector/src/zkp/index.ts | 111 ++ .../types}/contracts/LightweightStateV2.ts | 0 .../src/{ => zkp/types}/contracts/StateV2.ts | 0 .../src/{ => zkp/types}/contracts/common.ts | 0 .../factories/LightweightStateV2__factory.ts | 0 .../contracts/factories/StateV2__factory.ts | 0 .../types}/contracts/factories/index.ts | 0 .../src/zkp/types/contracts/index.ts | 11 + packages/connector/src/zkp/types/index.ts | 3 + packages/connector/src/zkp/types/params.ts | 36 + .../src/{types.ts => zkp/types/zkp.ts} | 143 +-- yarn.lock | 97 +- 38 files changed, 2180 insertions(+), 507 deletions(-) create mode 100644 packages/connector/abis/LightweightStateV2.json create mode 100644 packages/connector/abis/StateV2.json create mode 100644 packages/connector/src/consts/snap.ts delete mode 100644 packages/connector/src/contracts/index.ts create mode 100644 packages/connector/src/enums/index.ts create mode 100644 packages/connector/src/enums/snap.ts rename packages/connector/src/helpers/{promise.helpers.ts => promise.ts} (100%) rename packages/connector/src/{utils.ts => helpers/snap.ts} (70%) delete mode 100644 packages/connector/src/helpers/state-v2-helpers.ts create mode 100644 packages/connector/src/instances/index.ts create mode 100644 packages/connector/src/instances/snap.ts delete mode 100644 packages/connector/src/methods.ts delete mode 100644 packages/connector/src/snap.ts create mode 100644 packages/connector/src/types/index.ts create mode 100644 packages/connector/src/types/snap.ts create mode 100644 packages/connector/src/zkp/consts/general.ts create mode 100644 packages/connector/src/zkp/consts/index.ts create mode 100644 packages/connector/src/zkp/enums/general.ts create mode 100644 packages/connector/src/zkp/enums/index.ts create mode 100644 packages/connector/src/zkp/helpers/index.ts create mode 100644 packages/connector/src/zkp/helpers/state-v2-helpers.ts create mode 100644 packages/connector/src/zkp/index.ts rename packages/connector/src/{ => zkp/types}/contracts/LightweightStateV2.ts (100%) rename packages/connector/src/{ => zkp/types}/contracts/StateV2.ts (100%) rename packages/connector/src/{ => zkp/types}/contracts/common.ts (100%) rename packages/connector/src/{ => zkp/types}/contracts/factories/LightweightStateV2__factory.ts (100%) rename packages/connector/src/{ => zkp/types}/contracts/factories/StateV2__factory.ts (100%) rename packages/connector/src/{ => zkp/types}/contracts/factories/index.ts (100%) create mode 100644 packages/connector/src/zkp/types/contracts/index.ts create mode 100644 packages/connector/src/zkp/types/index.ts create mode 100644 packages/connector/src/zkp/types/params.ts rename packages/connector/src/{types.ts => zkp/types/zkp.ts} (56%) diff --git a/packages/connector/abis/LightweightStateV2.json b/packages/connector/abis/LightweightStateV2.json new file mode 100644 index 00000000..53337123 --- /dev/null +++ b/packages/connector/abis/LightweightStateV2.json @@ -0,0 +1,564 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "previousAdmin", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newAdmin", + "type": "address" + } + ], + "name": "AdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "beacon", + "type": "address" + } + ], + "name": "BeaconUpgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "newGistRoot", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "newIdentitesStatesRoot", + "type": "bytes32" + } + ], + "name": "SignedStateTransited", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "inputs": [], + "name": "P", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "signer_", + "type": "address" + }, + { + "internalType": "address", + "name": "sourceStateContract_", + "type": "address" + }, + { + "internalType": "string", + "name": "sourceChainName_", + "type": "string" + }, + { + "internalType": "string", + "name": "chainName_", + "type": "string" + } + ], + "name": "__LightweightStateV2_init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "signer_", + "type": "address" + }, + { + "internalType": "string", + "name": "chainName_", + "type": "string" + } + ], + "name": "__Signers_init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "chainName", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "newSignerPubKey_", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "signature_", + "type": "bytes" + } + ], + "name": "changeSigner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newSourceStateContract_", + "type": "address" + }, + { + "internalType": "bytes", + "name": "signature_", + "type": "bytes" + } + ], + "name": "changeSourceStateContract", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "methodId_", + "type": "uint8" + }, + { + "internalType": "address", + "name": "contractAddress_", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "signHash_", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "signature_", + "type": "bytes" + } + ], + "name": "checkSignatureAndIncrementNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getCurrentGISTRootInfo", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtTimestamp", + "type": "uint256" + } + ], + "internalType": "struct ILightweightStateV2.GistRootData", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getGISTRoot", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "root_", + "type": "uint256" + } + ], + "name": "getGISTRootInfo", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtTimestamp", + "type": "uint256" + } + ], + "internalType": "struct ILightweightStateV2.GistRootData", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "root_", + "type": "bytes32" + } + ], + "name": "getIdentitiesStatesRootData", + "outputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "root", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "setTimestamp", + "type": "uint256" + } + ], + "internalType": "struct ILightweightStateV2.IdentitiesStatesRootData", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "methodId_", + "type": "uint8" + }, + { + "internalType": "address", + "name": "contractAddress_", + "type": "address" + } + ], + "name": "getSigComponents", + "outputs": [ + { + "internalType": "string", + "name": "chainName_", + "type": "string" + }, + { + "internalType": "uint256", + "name": "nonce_", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "identitiesStatesRoot", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "root_", + "type": "bytes32" + } + ], + "name": "isIdentitiesStatesRootExists", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "nonces", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "proxiableUUID", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "newIdentitiesStatesRoot_", + "type": "bytes32" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtTimestamp", + "type": "uint256" + } + ], + "internalType": "struct ILightweightStateV2.GistRootData", + "name": "gistData_", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "proof_", + "type": "bytes" + } + ], + "name": "signedTransitState", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "signer", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "sourceChainName", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "sourceStateContract", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + } + ], + "name": "upgradeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation_", + "type": "address" + }, + { + "internalType": "bytes", + "name": "signature_", + "type": "bytes" + } + ], + "name": "upgradeToWithSig", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "methodId_", + "type": "uint8" + }, + { + "internalType": "address", + "name": "contractAddress_", + "type": "address" + }, + { + "internalType": "address", + "name": "newAddress_", + "type": "address" + }, + { + "internalType": "bytes", + "name": "signature_", + "type": "bytes" + } + ], + "name": "validateChangeAddressSignature", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/packages/connector/abis/StateV2.json b/packages/connector/abis/StateV2.json new file mode 100644 index 00000000..275db6bb --- /dev/null +++ b/packages/connector/abis/StateV2.json @@ -0,0 +1,945 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferStarted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [], + "name": "VERSION", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + } + ], + "name": "getGISTProof", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "existence", + "type": "bool" + }, + { + "internalType": "uint256[64]", + "name": "siblings", + "type": "uint256[64]" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "auxExistence", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "auxIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "auxValue", + "type": "uint256" + } + ], + "internalType": "struct IState.GistProof", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + } + ], + "name": "getGISTProofByBlock", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "existence", + "type": "bool" + }, + { + "internalType": "uint256[64]", + "name": "siblings", + "type": "uint256[64]" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "auxExistence", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "auxIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "auxValue", + "type": "uint256" + } + ], + "internalType": "struct IState.GistProof", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + } + ], + "name": "getGISTProofByRoot", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "existence", + "type": "bool" + }, + { + "internalType": "uint256[64]", + "name": "siblings", + "type": "uint256[64]" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "auxExistence", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "auxIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "auxValue", + "type": "uint256" + } + ], + "internalType": "struct IState.GistProof", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "getGISTProofByTime", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "existence", + "type": "bool" + }, + { + "internalType": "uint256[64]", + "name": "siblings", + "type": "uint256[64]" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "auxExistence", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "auxIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "auxValue", + "type": "uint256" + } + ], + "internalType": "struct IState.GistProof", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getGISTRoot", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "start", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "getGISTRootHistory", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedByRoot", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtBlock", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtBlock", + "type": "uint256" + } + ], + "internalType": "struct IState.GistRootInfo[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getGISTRootHistoryLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + } + ], + "name": "getGISTRootInfo", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedByRoot", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtBlock", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtBlock", + "type": "uint256" + } + ], + "internalType": "struct IState.GistRootInfo", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + } + ], + "name": "getGISTRootInfoByBlock", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedByRoot", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtBlock", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtBlock", + "type": "uint256" + } + ], + "internalType": "struct IState.GistRootInfo", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "getGISTRootInfoByTime", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "root", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedByRoot", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtBlock", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtBlock", + "type": "uint256" + } + ], + "internalType": "struct IState.GistRootInfo", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + } + ], + "name": "getStateInfoById", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "state", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedByState", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtBlock", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtBlock", + "type": "uint256" + } + ], + "internalType": "struct IState.StateInfo", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "state", + "type": "uint256" + } + ], + "name": "getStateInfoByIdAndState", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "state", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedByState", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtBlock", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtBlock", + "type": "uint256" + } + ], + "internalType": "struct IState.StateInfo", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "getStateInfoHistoryById", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "state", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedByState", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "createdAtBlock", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "replacedAtBlock", + "type": "uint256" + } + ], + "internalType": "struct IState.StateInfo[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + } + ], + "name": "getStateInfoHistoryLengthById", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVerifier", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + } + ], + "name": "idExists", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IStateTransitionVerifier", + "name": "verifierContractAddr", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pendingOwner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newVerifierAddr", + "type": "address" + } + ], + "name": "setVerifier", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "state", + "type": "uint256" + } + ], + "name": "stateExists", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldState", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "newState", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isOldStateGenesis", + "type": "bool" + }, + { + "internalType": "uint256[2]", + "name": "a", + "type": "uint256[2]" + }, + { + "internalType": "uint256[2][2]", + "name": "b", + "type": "uint256[2][2]" + }, + { + "internalType": "uint256[2]", + "name": "c", + "type": "uint256[2]" + } + ], + "name": "transitState", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/packages/connector/package.json b/packages/connector/package.json index 0540457c..4b24c343 100644 --- a/packages/connector/package.json +++ b/packages/connector/package.json @@ -35,6 +35,7 @@ "build:esm": "npx swc src -d ./dist/esm --config-file ./.swcrc -C module.type=es6 isModule=true --copy-files", "build:types": "tsc -p tsconfig.build.json --outDir ./dist/types --declaration --emitDeclarationOnly", "clean": "rm -rf dist", + "generate-ether-types": "typechain --target=ethers-v5 'abis/**/*.json' --out-dir src/zkp/types/contracts", "lint": "yarn run lint:style && yarn run lint:types", "lint:style": "eslint --color 'src/**/*.{js,ts,tsx}'", "lint:style:fix": "yarn run lint:style --fix", @@ -50,7 +51,9 @@ "@swc/cli": "^0.1.62", "@swc/core": "1.3.53", "@swc/jest": "^0.2.26", - "tsc-alias": "^1.8.8" + "@typechain/ethers-v5": "11.1.1", + "tsc-alias": "^1.8.8", + "typechain": "8.3.1" }, "publishConfig": { "access": "public" diff --git a/packages/connector/src/consts/general.ts b/packages/connector/src/consts/general.ts index ed7d4255..b6b1fdf2 100644 --- a/packages/connector/src/consts/general.ts +++ b/packages/connector/src/consts/general.ts @@ -1,2 +1 @@ -export const CORE_POLLING_INTERVAL = 5_000; export const SUPPORTED_METAMASK_VERSION = '11.5.0'; diff --git a/packages/connector/src/consts/index.ts b/packages/connector/src/consts/index.ts index 12bc2fe5..89dd1696 100644 --- a/packages/connector/src/consts/index.ts +++ b/packages/connector/src/consts/index.ts @@ -1 +1,2 @@ +export * from './snap'; export * from './general'; diff --git a/packages/connector/src/consts/snap.ts b/packages/connector/src/consts/snap.ts new file mode 100644 index 00000000..5993449f --- /dev/null +++ b/packages/connector/src/consts/snap.ts @@ -0,0 +1 @@ +export const defaultSnapOrigin = 'npm:@rarimo/rarime'; diff --git a/packages/connector/src/contracts/index.ts b/packages/connector/src/contracts/index.ts deleted file mode 100644 index 36c3c77b..00000000 --- a/packages/connector/src/contracts/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* Autogenerated file. Do not edit manually. */ -/* tslint:disable */ -/* eslint-disable */ -export type { LightweightStateV2 } from "./LightweightStateV2"; -export type { StateV2 } from "./StateV2"; -export * as factories from "./factories"; -export { LightweightStateV2__factory } from "./factories/LightweightStateV2__factory"; -export { StateV2__factory } from "./factories/StateV2__factory"; diff --git a/packages/connector/src/enums/index.ts b/packages/connector/src/enums/index.ts new file mode 100644 index 00000000..28b88c94 --- /dev/null +++ b/packages/connector/src/enums/index.ts @@ -0,0 +1 @@ +export * from './snap'; diff --git a/packages/connector/src/enums/snap.ts b/packages/connector/src/enums/snap.ts new file mode 100644 index 00000000..c49ccac1 --- /dev/null +++ b/packages/connector/src/enums/snap.ts @@ -0,0 +1,11 @@ +export enum RPCMethods { + CreateIdentity = 'create_identity', + SaveCredentials = 'save_credentials', + RemoveCredentials = 'remove_credentials', + CheckCredentialExistence = 'check_credential_existence', + CreateProof = 'create_proof', + CheckStateContractSync = 'check_state_contract_sync', + GetCredentials = 'get_credentials', + ExportIdentity = 'export_identity', + GetIdentity = 'get_identity', +} diff --git a/packages/connector/src/helpers/index.ts b/packages/connector/src/helpers/index.ts index 7a33cc59..2e054077 100644 --- a/packages/connector/src/helpers/index.ts +++ b/packages/connector/src/helpers/index.ts @@ -1 +1,3 @@ -export * from './state-v2-helpers'; +export * from './snap'; +export * from './promise'; +export * from './error-helper'; diff --git a/packages/connector/src/helpers/promise.helpers.ts b/packages/connector/src/helpers/promise.ts similarity index 100% rename from packages/connector/src/helpers/promise.helpers.ts rename to packages/connector/src/helpers/promise.ts diff --git a/packages/connector/src/utils.ts b/packages/connector/src/helpers/snap.ts similarity index 70% rename from packages/connector/src/utils.ts rename to packages/connector/src/helpers/snap.ts index fe7e3fe2..d2294a1d 100644 --- a/packages/connector/src/utils.ts +++ b/packages/connector/src/helpers/snap.ts @@ -1,8 +1,12 @@ import { compare } from 'compare-versions'; -import { defaultSnapOrigin } from '.'; -import { SUPPORTED_METAMASK_VERSION } from './consts'; -import type { GetSnapsResponse } from './types'; +import { SUPPORTED_METAMASK_VERSION } from '@/consts'; +import type { RPCMethods } from '@/enums'; +import type { + GetSnapsResponse, + SnapRequestParams, + SnapRequestsResponses, +} from '@/types'; export const getProvider = async () => { let mmFound = false; @@ -45,12 +49,6 @@ export const getProvider = async () => { return window.ethereum; }; -export const getWalletSnaps = async (): Promise => { - return await window.ethereum.request({ - method: 'wallet_getSnaps', - }); -}; - export const isMetamaskInstalled = async (): Promise => { try { const provider = await getProvider(); @@ -60,26 +58,6 @@ export const isMetamaskInstalled = async (): Promise => { } }; -export const isSnapInstalled = async ( - snapOrigin?: string, - version?: string, -): Promise => { - try { - await getProvider(); - const snapId = snapOrigin ?? defaultSnapOrigin; - return Boolean( - Object.values(await getWalletSnaps()).find( - (permission) => - permission.id === snapId && - (!version || permission.version === version), - ), - ); - } catch (e) { - console.log('Failed to obtain installed snaps', e); - return false; - } -}; - export const checkSnapSupport = async () => { const version = await window?.ethereum?.request?.({ method: 'web3_clientVersion', @@ -89,3 +67,26 @@ export const checkSnapSupport = async () => { const isMobile = version.endsWith('Mobile'); return compare(currentVersion, SUPPORTED_METAMASK_VERSION, '>=') && !isMobile; }; + +export const getWalletSnaps = async (): Promise => { + const provider = await getProvider(); + + return await provider.request({ + method: 'wallet_getSnaps', + }); +}; + +export const sendSnapMethod = async ( + request: { method: Method; params?: SnapRequestParams[Method] }, + snapId: string, +): Promise => { + const provider = await getProvider(); + + return await provider.request({ + method: 'wallet_invokeSnap', + params: { + request, + snapId, + }, + }); +}; diff --git a/packages/connector/src/helpers/state-v2-helpers.ts b/packages/connector/src/helpers/state-v2-helpers.ts deleted file mode 100644 index 7e5a9333..00000000 --- a/packages/connector/src/helpers/state-v2-helpers.ts +++ /dev/null @@ -1,113 +0,0 @@ -/* eslint-disable camelcase */ - -import type { TransactionRequest } from '@ethersproject/providers'; -import { utils } from 'ethers'; - -import { FetcherError } from './error-helper'; -import { sleep } from './promise.helpers'; -import { CORE_POLLING_INTERVAL } from '../consts'; -import { LightweightStateV2__factory } from '../contracts'; -import type { - ChainInfo, - StateInfo, - Operation, - OperationProof, - UpdateStateDetails, -} from '../types'; - -export const loadDataFromRarimoCore = async ( - url: string, - rarimoCoreUrl: string, - blockHeight?: string, -): Promise => { - const response = await fetch(`${rarimoCoreUrl}${url}`, { - headers: { - 'Content-Type': 'application/json', - ...(blockHeight && { 'X-Cosmos-Block-Height': blockHeight }), - }, - }); - - if (!response.ok) { - throw new FetcherError(response); - } - - return await response.json(); -}; - -export const getUpdateStateDetails = async ( - state: StateInfo, - operation: Operation, - rarimoCoreUrl: string, -): Promise => { - let operationProof; - do { - try { - operationProof = await loadDataFromRarimoCore( - `/rarimo/rarimo-core/rarimocore/operation/${state.lastUpdateOperationIndex}/proof`, - rarimoCoreUrl, - ); - } catch (e) { - if (e instanceof FetcherError && e.response.status === 400) { - await sleep(CORE_POLLING_INTERVAL); - } else { - throw e; - } - } - } while (!operationProof); - - const decodedPath = operationProof.path.map((el: string) => - utils.arrayify(el), - ); - const decodedSignature = operationProof.signature - ? utils.arrayify(operationProof.signature) - : undefined; - - if (!decodedSignature) { - throw new Error('Signature is not defined'); - } - - if (decodedSignature[64] !== undefined) { - decodedSignature[64] += 27; - } - - const proof = utils.defaultAbiCoder.encode( - ['bytes32[]', 'bytes'], - [decodedPath, decodedSignature], - ); - - return { - stateRootHash: operation.details.stateRootHash, - gistRootDataStruct: { - root: operation.details.GISTHash, - createdAtTimestamp: Number(operation.details.timestamp), - }, - proof, - }; -}; - -export const getUpdateStateTx = async ( - accountId: string, - chainInfo: ChainInfo, - state: StateInfo, - operation: Operation, - rarimoCoreUrl: string, - updateStateDetails?: UpdateStateDetails, -): Promise => { - const { stateRootHash, gistRootDataStruct, proof } = - updateStateDetails ?? - (await getUpdateStateDetails(state, operation, rarimoCoreUrl)); - - const contractInterface = LightweightStateV2__factory.createInterface(); - - const txData = contractInterface.encodeFunctionData('signedTransitState', [ - stateRootHash, - gistRootDataStruct, - proof, - ]); - return { - to: chainInfo.stateContractAddress, - from: accountId, - chainId: chainInfo.id, - data: txData, - }; -}; diff --git a/packages/connector/src/index.ts b/packages/connector/src/index.ts index 43f7a9c5..888ca84e 100644 --- a/packages/connector/src/index.ts +++ b/packages/connector/src/index.ts @@ -1,33 +1,5 @@ -import { MetamaskSnap } from './snap'; -import { checkSnapSupport, isMetamaskInstalled } from './utils'; -import versionJson from './version.json'; - -export { MetamaskSnap } from './snap'; +export * from './helpers'; +export * from './consts'; +export * from './enums'; export * from './types'; -export { isMetamaskInstalled, isSnapInstalled } from './utils'; - -export const defaultSnapOrigin = 'npm:@rarimo/rarime'; - -export const enableSnap = async ( - snapOrigin?: string, - version = versionJson.version, -): Promise => { - const snapId = snapOrigin ?? defaultSnapOrigin; - - if (!(await isMetamaskInstalled())) { - throw new Error('Metamask is not installed'); - } - - if (!(await checkSnapSupport())) { - throw new Error('Current version of MetaMask is not supported'); - } - - await window.ethereum.request({ - method: 'wallet_requestSnaps', - params: { - [snapId]: { ...(version && { version }) }, - }, - }); - - return new MetamaskSnap(snapId); -}; +export * from './zkp'; diff --git a/packages/connector/src/instances/index.ts b/packages/connector/src/instances/index.ts new file mode 100644 index 00000000..28b88c94 --- /dev/null +++ b/packages/connector/src/instances/index.ts @@ -0,0 +1 @@ +export * from './snap'; diff --git a/packages/connector/src/instances/snap.ts b/packages/connector/src/instances/snap.ts new file mode 100644 index 00000000..17311b47 --- /dev/null +++ b/packages/connector/src/instances/snap.ts @@ -0,0 +1,83 @@ +import versionJson from '../version.json'; + +import { defaultSnapOrigin } from '@/consts'; +import type { RPCMethods } from '@/enums'; +import { + checkSnapSupport, + getProvider, + getWalletSnaps, + isMetamaskInstalled, +} from '@/helpers'; +import type { SnapRequestParams, SnapRequestsResponses } from '@/types'; + +export class RarimeSnapBase { + public readonly snapId: string; + + public readonly version: string; + + public constructor( + snapId = defaultSnapOrigin, + version = versionJson.version, + ) { + this.snapId = snapId; + this.version = version; + } + + public async sendSnapRequest( + method: Method, + params?: SnapRequestParams[Method], + ): Promise { + const provider = await getProvider(); + + return await provider.request({ + method: 'wallet_invokeSnap', + params: { + request: { + method, + params, + }, + snapId: this.snapId, + }, + }); + } + + public async enable() { + const snapId = this.snapId ?? defaultSnapOrigin; + + if (!(await isMetamaskInstalled())) { + throw new Error('Metamask is not installed'); + } + + if (!(await checkSnapSupport())) { + throw new Error('Current version of MetaMask is not supported'); + } + + const provider = await getProvider(); + + return await provider.request({ + method: 'wallet_requestSnaps', + params: { + [snapId]: { ...(this.version && { version: this.version }) }, + }, + }); + } + + async isInstalled() { + try { + await getProvider(); + + const walletSnaps = await getWalletSnaps(); + + return Boolean( + Object.values(walletSnaps).find( + (permission) => + permission.id === this.snapId && + (!this.version || permission.version === this.version), + ), + ); + } catch (error) { + console.log('Failed to obtain installed snaps', error); + return false; + } + } +} diff --git a/packages/connector/src/methods.ts b/packages/connector/src/methods.ts deleted file mode 100644 index c9e29c4d..00000000 --- a/packages/connector/src/methods.ts +++ /dev/null @@ -1,148 +0,0 @@ -/* eslint-disable no-invalid-this */ -import { getUpdateStateDetails, getUpdateStateTx } from './helpers'; -import type { MetamaskSnap } from './snap'; -import type { - CheckCredentialExistenceRequestParams, - CreateIdentityRequestParams, - CreateProofRequestParams, - RemoveCredentialsRequestParams, - IdentityDidPair, - SaveCredentialsRequestParams, - SaveCredentialsResponse, - W3CCredential, - ZKPProofResponse, - ZKPProofSnapResponse, -} from './types'; -import { RPCMethods } from './types'; - -const sendSnapMethod = async ( - request: unknown, - snapId: string, -): Promise => { - return await window.ethereum.request({ - method: 'wallet_invokeSnap', - params: { - request, - snapId, - }, - }); -}; - -export const checkCredentialExistence = async function ( - this: MetamaskSnap, - params: CheckCredentialExistenceRequestParams, -): Promise { - return await sendSnapMethod( - { method: RPCMethods.CheckCredentialExistence, params }, - this.snapId, - ); -}; - -export const createIdentity = async function ( - this: MetamaskSnap, - params?: CreateIdentityRequestParams, -): Promise { - return await sendSnapMethod( - { method: RPCMethods.CreateIdentity, params }, - this.snapId, - ); -}; - -export const getIdentity = async function ( - this: MetamaskSnap, -): Promise { - return await sendSnapMethod( - { - method: RPCMethods.GetIdentity, - }, - this.snapId, - ); -}; - -export const saveCredentials = async function ( - this: MetamaskSnap, - params: SaveCredentialsRequestParams, -): Promise { - return await sendSnapMethod( - { method: RPCMethods.SaveCredentials, params }, - this.snapId, - ); -}; - -export const removeCredentials = async function ( - this: MetamaskSnap, - params: RemoveCredentialsRequestParams, -): Promise { - return await sendSnapMethod( - { method: RPCMethods.RemoveCredentials, params }, - this.snapId, - ); -}; - -export const createProof = async function ( - this: MetamaskSnap, - params: CreateProofRequestParams, -): Promise { - const snapResponse = (await sendSnapMethod( - { method: RPCMethods.CreateProof, params }, - this.snapId, - )) as ZKPProofSnapResponse; - - const updateStateDetails = await getUpdateStateDetails( - snapResponse.stateData, - snapResponse.operation, - snapResponse.rarimoCoreUrl, - ); - - let updateStateTx; - - if (!snapResponse.isSynced) { - updateStateTx = await getUpdateStateTx( - params.accountAddress!, - snapResponse.chainInfo, - snapResponse.stateData, - snapResponse.operation, - snapResponse.rarimoCoreUrl, - updateStateDetails, - ); - } - - return { - statesMerkleData: { - issuerId: snapResponse.issuerHexId, - state: snapResponse.stateData, - merkleProof: snapResponse.merkleProof.proof, - }, - zkpProof: snapResponse.zkpProof, - updateStateDetails, - - ...(updateStateTx && { updateStateTx }), - }; -}; - -export const checkStateContractSync = async function ( - this: MetamaskSnap, -): Promise { - return await sendSnapMethod( - { method: RPCMethods.CheckStateContractSync }, - this.snapId, - ); -}; - -export const getCredentials = async function ( - this: MetamaskSnap, -): Promise { - return await sendSnapMethod( - { method: RPCMethods.GetCredentials }, - this.snapId, - ); -}; - -export const exportIdentity = async function ( - this: MetamaskSnap, -): Promise { - return await sendSnapMethod( - { method: RPCMethods.ExportIdentity }, - this.snapId, - ); -}; diff --git a/packages/connector/src/snap.ts b/packages/connector/src/snap.ts deleted file mode 100644 index 17c40987..00000000 --- a/packages/connector/src/snap.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { - createIdentity, - createProof, - saveCredentials, - checkStateContractSync, - getCredentials, - checkCredentialExistence, - removeCredentials, - exportIdentity, - getIdentity, -} from './methods'; -import type { SnapConnector } from './types'; - -export class MetamaskSnap { - public readonly snapId: string; - - public constructor(snapId: string) { - this.snapId = snapId; - } - - public getConnector = async (): Promise => { - return { - createIdentity: createIdentity.bind(this), - saveCredentials: saveCredentials.bind(this), - removeCredentials: removeCredentials.bind(this), - createProof: createProof.bind(this), - checkStateContractSync: checkStateContractSync.bind(this), - getCredentials: getCredentials.bind(this), - checkCredentialExistence: checkCredentialExistence.bind(this), - exportIdentity: exportIdentity.bind(this), - getIdentity: getIdentity.bind(this), - }; - }; -} diff --git a/packages/connector/src/types/index.ts b/packages/connector/src/types/index.ts new file mode 100644 index 00000000..28b88c94 --- /dev/null +++ b/packages/connector/src/types/index.ts @@ -0,0 +1 @@ +export * from './snap'; diff --git a/packages/connector/src/types/snap.ts b/packages/connector/src/types/snap.ts new file mode 100644 index 00000000..9db026ec --- /dev/null +++ b/packages/connector/src/types/snap.ts @@ -0,0 +1,49 @@ +import type { RPCMethods } from '@/enums'; +import type { + CheckCredentialExistenceRequestParams, + CreateIdentityRequestParams, + CreateProofRequestParams, + IdentityDidPair, + RemoveCredentialsRequestParams, + SaveCredentialsRequestParams, + SaveCredentialsResponse, + W3CCredential, + ZKPProofSnapResponse, +} from '@/zkp'; + +export type GetSnapsResponse = { + [k: string]: { + permissionName?: string; + id?: string; + version?: string; + initialPermissions?: { [k: string]: unknown }; + }; +}; + +export type SnapRequestParams = { + [RPCMethods.CreateIdentity]: CreateIdentityRequestParams; + [RPCMethods.ExportIdentity]: never; + [RPCMethods.GetIdentity]: never; + + [RPCMethods.SaveCredentials]: SaveCredentialsRequestParams; + [RPCMethods.RemoveCredentials]: RemoveCredentialsRequestParams; + [RPCMethods.CheckCredentialExistence]: CheckCredentialExistenceRequestParams; + [RPCMethods.GetCredentials]: never; + + [RPCMethods.CheckStateContractSync]: never; + [RPCMethods.CreateProof]: CreateProofRequestParams; +}; + +export type SnapRequestsResponses = { + [RPCMethods.CreateIdentity]: IdentityDidPair; + [RPCMethods.ExportIdentity]: void; + [RPCMethods.GetIdentity]: IdentityDidPair; + + [RPCMethods.SaveCredentials]: SaveCredentialsResponse[]; + [RPCMethods.RemoveCredentials]: void; + [RPCMethods.CheckCredentialExistence]: SaveCredentialsResponse[]; + [RPCMethods.GetCredentials]: W3CCredential[]; + + [RPCMethods.CheckStateContractSync]: boolean; + [RPCMethods.CreateProof]: ZKPProofSnapResponse; +}; diff --git a/packages/connector/src/zkp/consts/general.ts b/packages/connector/src/zkp/consts/general.ts new file mode 100644 index 00000000..a7d568d4 --- /dev/null +++ b/packages/connector/src/zkp/consts/general.ts @@ -0,0 +1 @@ +export const CORE_POLLING_INTERVAL = 5_000; diff --git a/packages/connector/src/zkp/consts/index.ts b/packages/connector/src/zkp/consts/index.ts new file mode 100644 index 00000000..12bc2fe5 --- /dev/null +++ b/packages/connector/src/zkp/consts/index.ts @@ -0,0 +1 @@ +export * from './general'; diff --git a/packages/connector/src/zkp/enums/general.ts b/packages/connector/src/zkp/enums/general.ts new file mode 100644 index 00000000..49f0e5ed --- /dev/null +++ b/packages/connector/src/zkp/enums/general.ts @@ -0,0 +1,10 @@ +export enum CircuitId { + // AtomicQueryMTPV2 is a type for credentialAtomicQueryMTPV2.circom + AtomicQueryMTPV2 = 'credentialAtomicQueryMTPV2', + // AtomicQueryMTPV2OnChain is a type for credentialAtomicQueryMTPV2OnChain.circom + AtomicQueryMTPV2OnChain = 'credentialAtomicQueryMTPV2OnChain', + // AtomicQuerySig is a type for credentialAttrQuerySig.circom + AtomicQuerySigV2 = 'credentialAtomicQuerySigV2', + // AtomicQuerySigOnChain is a type for credentialAtomicQuerySigOnChain.circom + AtomicQuerySigV2OnChain = 'credentialAtomicQuerySigV2OnChain', +} diff --git a/packages/connector/src/zkp/enums/index.ts b/packages/connector/src/zkp/enums/index.ts new file mode 100644 index 00000000..12bc2fe5 --- /dev/null +++ b/packages/connector/src/zkp/enums/index.ts @@ -0,0 +1 @@ +export * from './general'; diff --git a/packages/connector/src/zkp/helpers/index.ts b/packages/connector/src/zkp/helpers/index.ts new file mode 100644 index 00000000..7a33cc59 --- /dev/null +++ b/packages/connector/src/zkp/helpers/index.ts @@ -0,0 +1 @@ +export * from './state-v2-helpers'; diff --git a/packages/connector/src/zkp/helpers/state-v2-helpers.ts b/packages/connector/src/zkp/helpers/state-v2-helpers.ts new file mode 100644 index 00000000..d0402b21 --- /dev/null +++ b/packages/connector/src/zkp/helpers/state-v2-helpers.ts @@ -0,0 +1,207 @@ +/* eslint-disable camelcase */ + +import type { TransactionRequest } from '@ethersproject/providers'; +import { providers, utils } from 'ethers'; + +import { FetcherError } from '@/helpers/error-helper'; +import { sleep } from '@/helpers/promise'; +import { CORE_POLLING_INTERVAL } from '@/zkp/consts'; +import type { + ChainZkpInfo, + StateInfo, + Operation, + OperationProof, + UpdateStateDetails, + StateProof, + OperationResponse, +} from '@/zkp/types'; +import { StateV2__factory } from '@/zkp/types'; +import { LightweightStateV2__factory } from '@/zkp/types/contracts'; + +export const loadDataFromRarimoCore = async ( + url: string, + rarimoCoreUrl: string, + blockHeight?: string, +): Promise => { + const response = await fetch(`${rarimoCoreUrl}${url}`, { + headers: { + 'Content-Type': 'application/json', + ...(blockHeight && { 'X-Cosmos-Block-Height': blockHeight }), + }, + }); + + if (!response.ok) { + throw new FetcherError(response); + } + + return await response.json(); +}; + +export const getUpdateStateDetails = async ( + state: StateInfo, + operation: Operation, + rarimoCoreUrl: string, +): Promise => { + let operationProof; + do { + try { + operationProof = await loadDataFromRarimoCore( + `/rarimo/rarimo-core/rarimocore/operation/${state.lastUpdateOperationIndex}/proof`, + rarimoCoreUrl, + ); + } catch (error) { + if (error instanceof FetcherError && error.response.status === 400) { + await sleep(CORE_POLLING_INTERVAL); + } else { + throw error; + } + } + } while (!operationProof); + + const decodedPath = operationProof.path.map((el: string) => + utils.arrayify(el), + ); + const decodedSignature = operationProof.signature + ? utils.arrayify(operationProof.signature) + : undefined; + + if (!decodedSignature) { + throw new Error('Signature is not defined'); + } + + if (decodedSignature[64] !== undefined) { + decodedSignature[64] += 27; + } + + const proof = utils.defaultAbiCoder.encode( + ['bytes32[]', 'bytes'], + [decodedPath, decodedSignature], + ); + + return { + stateRootHash: operation.details.stateRootHash, + gistRootDataStruct: { + root: operation.details.GISTHash, + createdAtTimestamp: Number(operation.details.timestamp), + }, + proof, + }; +}; + +export const getUpdateStateTx = async ( + accountId: string, + chainInfo: ChainZkpInfo, + state: StateInfo, + operation: Operation, + rarimoCoreUrl: string, + updateStateDetails?: UpdateStateDetails, +): Promise => { + const { stateRootHash, gistRootDataStruct, proof } = + updateStateDetails ?? + (await getUpdateStateDetails(state, operation, rarimoCoreUrl)); + + const contractInterface = LightweightStateV2__factory.createInterface(); + + const txData = contractInterface.encodeFunctionData('signedTransitState', [ + stateRootHash, + gistRootDataStruct, + proof, + ]); + return { + to: chainInfo.targetStateContractAddress, + from: accountId, + chainId: chainInfo.targetChainId, + data: txData, + }; +}; + +export const getGISTProof = async ({ + rpcUrl, + contractAddress, + userId, + rootHash, +}: { + rpcUrl: string; + contractAddress: string; + userId: string; + rootHash?: string; +}): Promise => { + const rawProvider = new providers.JsonRpcProvider(rpcUrl); + + const contractInstance = StateV2__factory.connect( + contractAddress, + rawProvider, + ); + + const data = rootHash + ? await contractInstance.getGISTProofByRoot(userId, rootHash) + : await contractInstance.getGISTProof(userId); + + return { + root: BigInt(data.root.toString()), + existence: data.existence, + siblings: data.siblings?.map((sibling) => BigInt(sibling.toString())), + index: BigInt(data.index.toString()), + value: BigInt(data.value.toString()), + auxExistence: data.auxExistence, + auxIndex: BigInt(data.auxIndex.toString()), + auxValue: BigInt(data.auxValue.toString()), + }; +}; + +// getRarimoGISTRoot returns the latest GIST root from the Rarimo state contract +export const getRarimoGISTRoot = async ( + chainInfo: ChainZkpInfo, +): Promise => { + const rawProvider = new providers.JsonRpcProvider( + chainInfo.targetRpcUrl, + 'any', + ); + + const contractInstance = StateV2__factory.connect( + chainInfo.targetStateContractAddress, + rawProvider, + ); + + const root = await contractInstance.getGISTRoot(); + + return BigInt(root.toString()); +}; + +// getCurrentChainGISTRoot returns the GIST root from a lightweight state contract deployed on the current chain +export const getCurrentChainGISTRoot = async ( + chainInfo: ChainZkpInfo, +): Promise => { + const provider = new providers.JsonRpcProvider(chainInfo.targetRpcUrl, 'any'); + + const contractInstance = LightweightStateV2__factory.connect( + chainInfo.targetStateContractAddress, + provider, + ); + const root = await contractInstance.getGISTRoot(); + return BigInt(root.toString()); +}; + +// checkIfStateSynced returns true if the GIST root from the Rarimo state contract matches the GIST root from the current chain +export const checkIfStateSynced = async ( + chainInfo: ChainZkpInfo, +): Promise => { + /* + NOTE: for now we assume that the state must be synced if the GIST roots don't match + some more sophisticated logic could be added here in the future + */ + const rarimoGISTRoot = await getRarimoGISTRoot(chainInfo); + + const currentChainGISTRoot = await getCurrentChainGISTRoot(chainInfo); + return rarimoGISTRoot === currentChainGISTRoot; +}; + +export const getCoreOperationByIndex = async ( + chainInfo: ChainZkpInfo, + index: string, +) => { + return loadDataFromRarimoCore( + `/rarimo/rarimo-core/rarimocore/operation/${index}`, + chainInfo.rarimoApiUrl, + ); +}; diff --git a/packages/connector/src/zkp/index.ts b/packages/connector/src/zkp/index.ts new file mode 100644 index 00000000..6eca7a53 --- /dev/null +++ b/packages/connector/src/zkp/index.ts @@ -0,0 +1,111 @@ +import versionJson from '../version.json'; + +import { defaultSnapOrigin } from '@/consts'; +import { RPCMethods } from '@/enums'; +import { RarimeSnapBase } from '@/instances'; +import type { SnapRequestParams, SnapRequestsResponses } from '@/types'; +import { getUpdateStateDetails, getUpdateStateTx } from '@/zkp/helpers'; +import type { ZKPProofResponse } from '@/zkp/types'; + +export class ZkpSnap extends RarimeSnapBase { + public constructor( + snapId = defaultSnapOrigin, + version = versionJson.version, + ) { + super(snapId, version); + } + + createIdentity = async ( + params?: SnapRequestParams[RPCMethods.CreateIdentity], + ): Promise => { + return this.sendSnapRequest(RPCMethods.CreateIdentity, params); + }; + + exportIdentity = async (): Promise< + SnapRequestsResponses[RPCMethods.ExportIdentity] + > => { + return this.sendSnapRequest(RPCMethods.ExportIdentity); + }; + + getIdentity = async (): Promise< + SnapRequestsResponses[RPCMethods.GetIdentity] + > => { + return this.sendSnapRequest(RPCMethods.GetIdentity); + }; + + checkCredentialExistence = async ( + params: SnapRequestParams[RPCMethods.CheckCredentialExistence], + ): Promise => { + return this.sendSnapRequest(RPCMethods.CheckCredentialExistence, params); + }; + + saveCredentials = async ( + params: SnapRequestParams[RPCMethods.SaveCredentials], + ): Promise => { + return this.sendSnapRequest(RPCMethods.SaveCredentials, params); + }; + + removeCredentials = async ( + params: SnapRequestParams[RPCMethods.RemoveCredentials], + ): Promise => { + return this.sendSnapRequest(RPCMethods.RemoveCredentials, params); + }; + + getCredentials = async (): Promise< + SnapRequestsResponses[RPCMethods.GetCredentials] + > => { + return this.sendSnapRequest(RPCMethods.GetCredentials); + }; + + checkStateContractSync = async (): Promise< + SnapRequestsResponses[RPCMethods.CheckStateContractSync] + > => { + return this.sendSnapRequest(RPCMethods.CheckStateContractSync); + }; + + createProof = async ( + params: SnapRequestParams[RPCMethods.CreateProof], + ): Promise => { + const snapResponse = await this.sendSnapRequest( + RPCMethods.CreateProof, + params, + ); + + const updateStateDetails = await getUpdateStateDetails( + snapResponse.stateData, + snapResponse.operation, + snapResponse.rarimoCoreUrl, + ); + + let updateStateTx; + + if (!snapResponse.isSynced) { + updateStateTx = await getUpdateStateTx( + params.accountAddress!, + snapResponse.chainInfo, + snapResponse.stateData, + snapResponse.operation, + snapResponse.rarimoCoreUrl, + updateStateDetails, + ); + } + + return { + statesMerkleData: { + issuerId: snapResponse.issuerHexId, + state: snapResponse.stateData, + merkleProof: snapResponse.merkleProof.proof, + }, + + zkpProof: snapResponse.zkpProof, + updateStateDetails, + + ...(updateStateTx && { updateStateTx }), + }; + }; +} + +export * from './consts'; +export * from './helpers'; +export * from './types'; +export * from './enums'; diff --git a/packages/connector/src/contracts/LightweightStateV2.ts b/packages/connector/src/zkp/types/contracts/LightweightStateV2.ts similarity index 100% rename from packages/connector/src/contracts/LightweightStateV2.ts rename to packages/connector/src/zkp/types/contracts/LightweightStateV2.ts diff --git a/packages/connector/src/contracts/StateV2.ts b/packages/connector/src/zkp/types/contracts/StateV2.ts similarity index 100% rename from packages/connector/src/contracts/StateV2.ts rename to packages/connector/src/zkp/types/contracts/StateV2.ts diff --git a/packages/connector/src/contracts/common.ts b/packages/connector/src/zkp/types/contracts/common.ts similarity index 100% rename from packages/connector/src/contracts/common.ts rename to packages/connector/src/zkp/types/contracts/common.ts diff --git a/packages/connector/src/contracts/factories/LightweightStateV2__factory.ts b/packages/connector/src/zkp/types/contracts/factories/LightweightStateV2__factory.ts similarity index 100% rename from packages/connector/src/contracts/factories/LightweightStateV2__factory.ts rename to packages/connector/src/zkp/types/contracts/factories/LightweightStateV2__factory.ts diff --git a/packages/connector/src/contracts/factories/StateV2__factory.ts b/packages/connector/src/zkp/types/contracts/factories/StateV2__factory.ts similarity index 100% rename from packages/connector/src/contracts/factories/StateV2__factory.ts rename to packages/connector/src/zkp/types/contracts/factories/StateV2__factory.ts diff --git a/packages/connector/src/contracts/factories/index.ts b/packages/connector/src/zkp/types/contracts/factories/index.ts similarity index 100% rename from packages/connector/src/contracts/factories/index.ts rename to packages/connector/src/zkp/types/contracts/factories/index.ts diff --git a/packages/connector/src/zkp/types/contracts/index.ts b/packages/connector/src/zkp/types/contracts/index.ts new file mode 100644 index 00000000..9b4a6d28 --- /dev/null +++ b/packages/connector/src/zkp/types/contracts/index.ts @@ -0,0 +1,11 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { + ILightweightStateV2, + LightweightStateV2, +} from './LightweightStateV2'; +export type { StateV2 } from './StateV2'; +export * as factories from './factories'; +export { LightweightStateV2__factory } from './factories/LightweightStateV2__factory'; +export { StateV2__factory } from './factories/StateV2__factory'; diff --git a/packages/connector/src/zkp/types/index.ts b/packages/connector/src/zkp/types/index.ts new file mode 100644 index 00000000..1cbd3167 --- /dev/null +++ b/packages/connector/src/zkp/types/index.ts @@ -0,0 +1,3 @@ +export * from './params'; +export * from './zkp'; +export * from './contracts'; diff --git a/packages/connector/src/zkp/types/params.ts b/packages/connector/src/zkp/types/params.ts new file mode 100644 index 00000000..0889ec75 --- /dev/null +++ b/packages/connector/src/zkp/types/params.ts @@ -0,0 +1,36 @@ +import type { CreateProofRequest } from './zkp'; + +export type CreateIdentityRequestParams = { + privateKeyHex?: string; +}; + +export type SaveCredentialsRequestParams = { + body: { + Credentials: [ + { + description: string; + id: string; + }, + ]; + url: string; + }; + from: string; + id: string; + threadID?: string; + to: string; + typ?: string; + type: string; +}; + +export type CheckCredentialExistenceRequestParams = { + claimOffer?: SaveCredentialsRequestParams; + proofRequest?: CreateProofRequestParams; +}; + +export type RemoveCredentialsRequestParams = { + ids: string[]; +}; + +export type CreateProofRequestParams = CreateProofRequest & { + issuerDid: string; +}; diff --git a/packages/connector/src/types.ts b/packages/connector/src/zkp/types/zkp.ts similarity index 56% rename from packages/connector/src/types.ts rename to packages/connector/src/zkp/types/zkp.ts index eaf20ed5..12169a21 100644 --- a/packages/connector/src/types.ts +++ b/packages/connector/src/zkp/types/zkp.ts @@ -1,5 +1,7 @@ import type { TransactionRequest } from '@ethersproject/providers'; +import type { CircuitId } from '@/zkp/enums'; + declare global { // eslint-disable-next-line @typescript-eslint/consistent-type-definitions interface Window { @@ -7,85 +9,29 @@ declare global { } } -export enum RPCMethods { - CreateIdentity = 'create_identity', - SaveCredentials = 'save_credentials', - RemoveCredentials = 'remove_credentials', - CheckCredentialExistence = 'check_credential_existence', - CreateProof = 'create_proof', - CheckStateContractSync = 'check_state_contract_sync', - GetCredentials = 'get_credentials', - ExportIdentity = 'export_identity', - GetIdentity = 'get_identity', -} +// TODO: remove +export type RarimoNetworkType = 'mainnet' | 'beta'; -export type SaveCredentialsResponse = Pick & - Pick; +export type ChainZkpInfo = { + targetChainId: number; + targetRpcUrl: string; + targetStateContractAddress: string; + + rarimoApiUrl: string; + rarimoEvmRpcApiUrl: string; + rarimoStateContractAddress: string; -export type SnapConnector = { - createIdentity(params?: CreateIdentityRequestParams): Promise<{ - identityIdString: string; - identityIdBigIntString: string; - }>; - saveCredentials( - params: SaveCredentialsRequestParams, - ): Promise; - removeCredentials(params: RemoveCredentialsRequestParams): Promise; - createProof(params: CreateProofRequestParams): Promise; - checkStateContractSync(): Promise; - getCredentials(): Promise; - checkCredentialExistence( - params: CheckCredentialExistenceRequestParams, - ): Promise; - exportIdentity(): Promise; - getIdentity(): Promise; + rarimoNetworkType: RarimoNetworkType; }; +export type SaveCredentialsResponse = Pick & + Pick; + export type IdentityDidPair = { identityIdString: string; identityIdBigIntString: string; }; -export type GetSnapsResponse = { - [k: string]: { - permissionName?: string; - id?: string; - version?: string; - initialPermissions?: { [k: string]: unknown }; - }; -}; - -export type CreateIdentityRequestParams = { - privateKeyHex?: string; -}; - -export type CheckCredentialExistenceRequestParams = { - claimOffer?: SaveCredentialsRequestParams; - proofRequest?: CreateProofRequestParams; -}; - -export type SaveCredentialsRequestParams = { - body: { - Credentials: [ - { - description: string; - id: string; - }, - ]; - url: string; - }; - from: string; - id: string; - threadID?: string; - to: string; - typ?: string; - type: string; -}; - -export type RemoveCredentialsRequestParams = { - ids: string[]; -}; - export type CredentialStatus = { id: string; type: string; @@ -121,23 +67,11 @@ export type ProofQuery = { type?: string[]; }; -export type CreateProofRequestParams = { - id?: number; - accountAddress?: string; // Metamask user address for onchain proofs - issuerDid: string; - circuitId: - | 'credentialAtomicQueryMTPV2' - | 'credentialAtomicQueryMTPV2OnChain' - | 'credentialAtomicQuerySigV2' - | 'credentialAtomicQuerySigV2OnChain'; - challenge?: string; // bigint string - query: ProofQuery; -}; - export type ZKProof = { proof: ProofData; pub_signals: string[]; }; + export type ProofData = { pi_a: string[]; pi_b: string[][]; @@ -149,6 +83,7 @@ export type StateInfo = { index: string; hash: string; createdAtTimestamp: string; + createdAtBlock: string; lastUpdateOperationIndex: string; }; @@ -195,22 +130,13 @@ export type Operation = { timestamp: string; }; -export type RarimoNetworkType = 'mainnet' | 'beta'; - -export type ChainInfo = { - id: number; - rpcUrl: string; - stateContractAddress: string; - rarimoNetworkType: RarimoNetworkType; -}; - export type OperationProof = { path: string[]; signature: string; }; export type ZKPProofSnapResponse = { - chainInfo: ChainInfo; + chainInfo: ChainZkpInfo; rarimoCoreUrl: string; isSynced: boolean; @@ -224,3 +150,34 @@ export type ZKPProofSnapResponse = { zkpProof: ZKProof; }; + +export type CreateProofRequest = { + id?: number; + accountAddress?: string; + circuitId: CircuitId; + challenge?: string; // bigint string + query: ProofQuery; +}; + +export type StateProof = { + root: bigint; + existence: boolean; + siblings: bigint[]; + index: bigint; + value: bigint; + auxExistence: boolean; + auxIndex: bigint; + auxValue: bigint; +}; + +export type MerkleProof = { + proof: string[]; +}; + +export type GetStateInfoResponse = { + state: StateInfo; +}; + +export type OperationResponse = { + operation: Operation; +}; diff --git a/yarn.lock b/yarn.lock index f7f2244d..c6738256 100644 --- a/yarn.lock +++ b/yarn.lock @@ -104,13 +104,13 @@ __metadata: languageName: node linkType: hard -"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.12.13, @babel/code-frame@npm:^7.23.5, @babel/code-frame@npm:^7.24.1": - version: 7.24.1 - resolution: "@babel/code-frame@npm:7.24.1" +"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.12.13, @babel/code-frame@npm:^7.23.5, @babel/code-frame@npm:^7.24.1, @babel/code-frame@npm:^7.24.2": + version: 7.24.2 + resolution: "@babel/code-frame@npm:7.24.2" dependencies: - "@babel/highlight": "npm:^7.24.1" + "@babel/highlight": "npm:^7.24.2" picocolors: "npm:^1.0.0" - checksum: 10/71da2249ea5cea5f0cb4c6e0052e921574d16ae415c5b876123787d160abc98442a91701834c875363dadd75d200897aa278336c505335722298982f793bdf89 + checksum: 10/7db8f5b36ffa3f47a37f58f61e3d130b9ecad21961f3eede7e2a4ac2c7e4a5efb6e9d03a810c669bc986096831b6c0dfc2c3082673d93351b82359c1b03e0590 languageName: node linkType: hard @@ -122,11 +122,11 @@ __metadata: linkType: hard "@babel/core@npm:^7.11.6, @babel/core@npm:^7.12.3, @babel/core@npm:^7.14.0, @babel/core@npm:^7.22.9, @babel/core@npm:^7.23.2, @babel/core@npm:^7.23.9": - version: 7.24.1 - resolution: "@babel/core@npm:7.24.1" + version: 7.24.3 + resolution: "@babel/core@npm:7.24.3" dependencies: "@ampproject/remapping": "npm:^2.2.0" - "@babel/code-frame": "npm:^7.24.1" + "@babel/code-frame": "npm:^7.24.2" "@babel/generator": "npm:^7.24.1" "@babel/helper-compilation-targets": "npm:^7.23.6" "@babel/helper-module-transforms": "npm:^7.23.3" @@ -140,7 +140,7 @@ __metadata: gensync: "npm:^1.0.0-beta.2" json5: "npm:^2.2.3" semver: "npm:^6.3.1" - checksum: 10/f8c153acd619a5d17caee7aff052a2aa306ceda280ffc07182d7b5dd40c41c7511ae89d64bc23ec5555e4639fc9c87ceb7b4afc12252acab548ebb7654397680 + checksum: 10/3a7b9931fe0d93c500dcdb6b36f038b0f9d5090c048818e62aa8321c8f6e8ccc3d47373f0b40591c1fe3b13e5096bacabb1ade83f9f4d86f57878c39a9d1ade1 languageName: node linkType: hard @@ -269,12 +269,12 @@ __metadata: languageName: node linkType: hard -"@babel/helper-module-imports@npm:^7.22.15, @babel/helper-module-imports@npm:^7.24.1": - version: 7.24.1 - resolution: "@babel/helper-module-imports@npm:7.24.1" +"@babel/helper-module-imports@npm:^7.22.15, @babel/helper-module-imports@npm:^7.24.1, @babel/helper-module-imports@npm:^7.24.3": + version: 7.24.3 + resolution: "@babel/helper-module-imports@npm:7.24.3" dependencies: "@babel/types": "npm:^7.24.0" - checksum: 10/f771c1e8776890d85c2af06a6a36410cb41ff4bbcf162e7eecce7d53ebdc5196cc38c3abea3a06df9d778bb20edccb2909dfb8187ae82730e4d021329b631921 + checksum: 10/42fe124130b78eeb4bb6af8c094aa749712be0f4606f46716ce74bc18a5ea91c918c547c8bb2307a2e4b33f163e4ad2cb6a7b45f80448e624eae45b597ea3499 languageName: node linkType: hard @@ -405,15 +405,15 @@ __metadata: languageName: node linkType: hard -"@babel/highlight@npm:^7.24.1": - version: 7.24.1 - resolution: "@babel/highlight@npm:7.24.1" +"@babel/highlight@npm:^7.24.2": + version: 7.24.2 + resolution: "@babel/highlight@npm:7.24.2" dependencies: "@babel/helper-validator-identifier": "npm:^7.22.20" chalk: "npm:^2.4.2" js-tokens: "npm:^4.0.0" picocolors: "npm:^1.0.0" - checksum: 10/5d9ad31006f462d3863e9c73004bd46d94d2a4144b3fcc1c9945d8a82411d05477d47466a1121f1d1dea986780145bf934e8b2809c6f056b2203fe481b4d471d + checksum: 10/4555124235f34403bb28f55b1de58edf598491cc181c75f8afc8fe529903cb598cd52fe3bf2faab9bc1f45c299681ef0e44eea7a848bb85c500c5a4fe13f54f6 languageName: node linkType: hard @@ -752,9 +752,9 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-transform-async-generator-functions@npm:^7.24.1": - version: 7.24.1 - resolution: "@babel/plugin-transform-async-generator-functions@npm:7.24.1" +"@babel/plugin-transform-async-generator-functions@npm:^7.24.3": + version: 7.24.3 + resolution: "@babel/plugin-transform-async-generator-functions@npm:7.24.3" dependencies: "@babel/helper-environment-visitor": "npm:^7.22.20" "@babel/helper-plugin-utils": "npm:^7.24.0" @@ -762,7 +762,7 @@ __metadata: "@babel/plugin-syntax-async-generators": "npm:^7.8.4" peerDependencies: "@babel/core": ^7.0.0-0 - checksum: 10/d4d31965395e3da8d060912ae85efc3dc7d6de5dba9919230b507a373cb51df4aa515fcc130b0c838aa77fe9bc4ede34f14f925570a6a280185988984f92dd51 + checksum: 10/4ccc3755a3d51544cd43575db2c5c2ef42cdcd35bd5940d13cdf23f04c75496290e79ea585a62427ec6bd508a1bffb329e01556cd1114be9b38ae4254935cd19 languageName: node linkType: hard @@ -1256,10 +1256,10 @@ __metadata: linkType: hard "@babel/plugin-transform-runtime@npm:^7.13.2": - version: 7.24.1 - resolution: "@babel/plugin-transform-runtime@npm:7.24.1" + version: 7.24.3 + resolution: "@babel/plugin-transform-runtime@npm:7.24.3" dependencies: - "@babel/helper-module-imports": "npm:^7.24.1" + "@babel/helper-module-imports": "npm:^7.24.3" "@babel/helper-plugin-utils": "npm:^7.24.0" babel-plugin-polyfill-corejs2: "npm:^0.4.10" babel-plugin-polyfill-corejs3: "npm:^0.10.1" @@ -1267,7 +1267,7 @@ __metadata: semver: "npm:^6.3.1" peerDependencies: "@babel/core": ^7.0.0-0 - checksum: 10/d59944d0ca3de08b15154bce4b62185bf3da3168a9792cef172bf351e94048ae93875cb35a8dc23567048de47861c6ed22540f77396014a40b0891dfc83e72e8 + checksum: 10/7f545c628993b527ae1cb028106168ec29873160a5d98aed947509b61e826fa52b6e2bd2c56504b4a5084555becc9841fa7842e61f822a050dd6ff5baff726ce languageName: node linkType: hard @@ -1389,8 +1389,8 @@ __metadata: linkType: hard "@babel/preset-env@npm:^7.23.2": - version: 7.24.1 - resolution: "@babel/preset-env@npm:7.24.1" + version: 7.24.3 + resolution: "@babel/preset-env@npm:7.24.3" dependencies: "@babel/compat-data": "npm:^7.24.1" "@babel/helper-compilation-targets": "npm:^7.23.6" @@ -1419,7 +1419,7 @@ __metadata: "@babel/plugin-syntax-top-level-await": "npm:^7.14.5" "@babel/plugin-syntax-unicode-sets-regex": "npm:^7.18.6" "@babel/plugin-transform-arrow-functions": "npm:^7.24.1" - "@babel/plugin-transform-async-generator-functions": "npm:^7.24.1" + "@babel/plugin-transform-async-generator-functions": "npm:^7.24.3" "@babel/plugin-transform-async-to-generator": "npm:^7.24.1" "@babel/plugin-transform-block-scoped-functions": "npm:^7.24.1" "@babel/plugin-transform-block-scoping": "npm:^7.24.1" @@ -1468,13 +1468,13 @@ __metadata: "@babel/plugin-transform-unicode-sets-regex": "npm:^7.24.1" "@babel/preset-modules": "npm:0.1.6-no-external-plugins" babel-plugin-polyfill-corejs2: "npm:^0.4.10" - babel-plugin-polyfill-corejs3: "npm:^0.10.1" + babel-plugin-polyfill-corejs3: "npm:^0.10.4" babel-plugin-polyfill-regenerator: "npm:^0.6.1" core-js-compat: "npm:^3.31.0" semver: "npm:^6.3.1" peerDependencies: "@babel/core": ^7.0.0-0 - checksum: 10/330ff67d4522fba0dd4a173f6b5649e947488dc7275dd2ae86e1e9be665fc6cdbcadce939671ece86c0683a98464a88dd7e70bd7120c923c26498ba596cecc8b + checksum: 10/42de398cb7655f3748a03f9f5ca6132dd8e84315ccf286e47740455dfb5be6358df7cfcbecf84426c14176a4d02d0b0b3c97ddf6c5c4c8fb7f1f307692a103ee languageName: node linkType: hard @@ -4822,9 +4822,11 @@ __metadata: "@swc/cli": "npm:^0.1.62" "@swc/core": "npm:1.3.53" "@swc/jest": "npm:^0.2.26" + "@typechain/ethers-v5": "npm:11.1.1" compare-versions: "npm:^6.1.0" ethers: "npm:5.7.2" tsc-alias: "npm:^1.8.8" + typechain: "npm:8.3.1" languageName: unknown linkType: soft @@ -6708,15 +6710,16 @@ __metadata: linkType: hard "array.prototype.findlastindex@npm:^1.2.3": - version: 1.2.4 - resolution: "array.prototype.findlastindex@npm:1.2.4" + version: 1.2.5 + resolution: "array.prototype.findlastindex@npm:1.2.5" dependencies: - call-bind: "npm:^1.0.5" + call-bind: "npm:^1.0.7" define-properties: "npm:^1.2.1" - es-abstract: "npm:^1.22.3" + es-abstract: "npm:^1.23.2" es-errors: "npm:^1.3.0" + es-object-atoms: "npm:^1.0.0" es-shim-unscopables: "npm:^1.0.2" - checksum: 10/12d7de8da619065b9d4c40550d11c13f2fbbc863c4270ef01d022f49ef16fbe9022441ee9d60b1e952853c661dd4b3e05c21e4348d4631c6d93ddf802a252296 + checksum: 10/7c5c821f357cd53ab6cc305de8086430dd8d7a2485db87b13f843e868055e9582b1fd338f02338f67fc3a1603ceaf9610dd2a470b0b506f9d18934780f95b246 languageName: node linkType: hard @@ -6948,15 +6951,15 @@ __metadata: languageName: node linkType: hard -"babel-plugin-polyfill-corejs3@npm:^0.10.1": - version: 0.10.1 - resolution: "babel-plugin-polyfill-corejs3@npm:0.10.1" +"babel-plugin-polyfill-corejs3@npm:^0.10.1, babel-plugin-polyfill-corejs3@npm:^0.10.4": + version: 0.10.4 + resolution: "babel-plugin-polyfill-corejs3@npm:0.10.4" dependencies: "@babel/helper-define-polyfill-provider": "npm:^0.6.1" - core-js-compat: "npm:^3.36.0" + core-js-compat: "npm:^3.36.1" peerDependencies: "@babel/core": ^7.4.0 || ^8.0.0-0 <8.0.0 - checksum: 10/88c3a644bb10df3052311339dca5ae0d440015f1feb8a4597f17826acaeeb61b6d01f3cc8d0fed200cb69d38345b28fe68e41ed8ef9d4fd1152fea0848ce0fc4 + checksum: 10/a69ed5a95bb55e9b7ea37307d56113f7e24054d479c15de6d50fa61388b5334bed1f9b6414cde6c575fa910a4de4d1ab4f2d22720967d57c4fec9d1b8f61b355 languageName: node linkType: hard @@ -7605,9 +7608,9 @@ __metadata: linkType: hard "caip@npm:^1.1.0, caip@npm:~1.1.0": - version: 1.1.0 - resolution: "caip@npm:1.1.0" - checksum: 10/54db513db4532fa14b408e920a2aa832449807250f70c77d5df328a8304354a94d44e4e65c14601759ae653008ab229336f604907feb423c79cc13e6f7704897 + version: 1.1.1 + resolution: "caip@npm:1.1.1" + checksum: 10/eb782d22ba47f1e632f5345e29e199d0599cd6d33d06d2da180f042a406706d832d599753c0041ba8a24dde8d317e408eae8d95d984ccbe0884be1c0fbd09907 languageName: node linkType: hard @@ -8286,7 +8289,7 @@ __metadata: languageName: node linkType: hard -"core-js-compat@npm:^3.31.0, core-js-compat@npm:^3.36.0": +"core-js-compat@npm:^3.31.0, core-js-compat@npm:^3.36.1": version: 3.36.1 resolution: "core-js-compat@npm:3.36.1" dependencies: @@ -9019,9 +9022,9 @@ __metadata: linkType: hard "electron-to-chromium@npm:^1.4.668": - version: 1.4.710 - resolution: "electron-to-chromium@npm:1.4.710" - checksum: 10/9f20e58d35350141e3c8d8ea577249cacf91e91ac57be2ad631606c4fb2ee627c6054e4dff152800c438faa1dc1cd14ae244a9e270eaec11821e0de263ff5de5 + version: 1.4.711 + resolution: "electron-to-chromium@npm:1.4.711" + checksum: 10/48ae0e074d4c2fe4594aded24547c31ee010732a40a970751b4205dc2397f2ceeaafcded9fa03079d0453cc514a0d72ff38992235328d056bd266722452a4e13 languageName: node linkType: hard