diff --git a/.changeset/dirty-pillows-hear.md b/.changeset/dirty-pillows-hear.md new file mode 100644 index 0000000..d9671d7 --- /dev/null +++ b/.changeset/dirty-pillows-hear.md @@ -0,0 +1,5 @@ +--- +"rankify-js": minor +--- + +Added changes needed to support multipass as stanadlone package diff --git a/package.json b/package.json index 3e36171..16b3873 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,9 @@ "lint": "eslint", "prebuild": "jq '.type = \"commonjs\"' package.json > temp.json && mv temp.json package.json", "build-esm": "tsc --project tsconfig.esm.json", - "build-all": "yarn run build-commonjs && yarn run build-esm", + "build-all": "pnpm run build-commonjs && pnpm run build-esm", "build-commonjs": "tsc --project tsconfig.commonjs.json", - "build": "yarn build-all && node ./copyPackageFile.js prod", + "build": "pnpm build-all && node ./copyPackageFile.js prod", "postbuild": "jq '.type = \"module\"' package.json > temp.json && mv temp.json package.json && cp README.md dist && cp -r .changeset ./dist/.changeset && prettier --write \"dist/**/*.{ts,js,json}\" && cd ./dist && pnpm install", "dist": "changeset && changeset version && pnpm build && cp -r .changeset ./dist && cd dist && pnpm changeset publish", "version": "changeset version", @@ -37,6 +37,7 @@ "dependencies": { "@ethersproject/abi": "^5.7.0", "@nomiclabs/hardhat-ethers": "^2.2.3", + "@peeramid-labs/multipass": "^0.2.0", "@peersky/eth-auth": "^2.0.0", "crypto-js": "^4.1.1", "ethers": "^5.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 008a38e..5350d0a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@nomiclabs/hardhat-ethers': specifier: ^2.2.3 version: 2.2.3(ethers@5.7.2)(hardhat@2.19.1(ts-node@10.9.1(@types/node@17.0.45)(typescript@5.3.2))(typescript@5.3.2)) + '@peeramid-labs/multipass': + specifier: ^0.2.0 + version: 0.2.0(hardhat@2.19.1(ts-node@10.9.1(@types/node@17.0.45)(typescript@5.3.2))(typescript@5.3.2)) '@peersky/eth-auth': specifier: ^2.0.0 version: 2.1.1 @@ -449,9 +452,20 @@ packages: '@openzeppelin/contracts-upgradeable@4.9.6': resolution: {integrity: sha512-m4iHazOsOCv1DgM7eD7GupTJ+NFVujRZt1wzddDPSVGpWdKq1SKkla5htKG7+IS4d2XOCtzkUNwRZ7Vq5aEUMA==} + '@openzeppelin/contracts-upgradeable@5.1.0': + resolution: {integrity: sha512-AIElwP5Ck+cslNE+Hkemf5SxjJoF4wBvvjxc27Rp+9jaPs/CLIaUBMYe1FNzhdiN0cYuwGRmYaRHmmntuiju4Q==} + peerDependencies: + '@openzeppelin/contracts': 5.1.0 + '@openzeppelin/contracts@4.9.6': resolution: {integrity: sha512-xSmezSupL+y9VkHZJGDoCBpmnB2ogM13ccaYDWqJTfS3dbuHkgjuwDFUmaFauBCboQMGB/S5UqUl2y54X99BmA==} + '@openzeppelin/contracts@5.1.0': + resolution: {integrity: sha512-p1ULhl7BXzjjbha5aqst+QMLY+4/LCWADXOCsmLHRM77AqiPjnd9vvUN9sosUfhL9JGKpZ0TjEGxgvnizmWGSA==} + + '@peeramid-labs/multipass@0.2.0': + resolution: {integrity: sha512-jLbGmZOfJUjkRaxtyqWTtEw7ScnANgNqvHV2OEQa9B+0YGVtQ//di8hxIXaGL4JgErlQAEecieTJmTtuwVewXQ==} + '@peersky/eth-auth@2.1.1': resolution: {integrity: sha512-vhz2IoSsYyiEL/wBtP250LGj1gwB4zsKelq4pAGG4woqb7EREM6V1lHG5kWIwtepGygAo/SwHK8DC5tEMXcWVQ==} @@ -3487,8 +3501,37 @@ snapshots: '@openzeppelin/contracts-upgradeable@4.9.6': {} + '@openzeppelin/contracts-upgradeable@5.1.0(@openzeppelin/contracts@5.1.0)': + dependencies: + '@openzeppelin/contracts': 5.1.0 + '@openzeppelin/contracts@4.9.6': {} + '@openzeppelin/contracts@5.1.0': {} + + '@peeramid-labs/multipass@0.2.0(hardhat@2.19.1(ts-node@10.9.1(@types/node@17.0.45)(typescript@5.3.2))(typescript@5.3.2))': + dependencies: + '@ethersproject/abi': 5.7.0 + '@ethersproject/providers': 5.7.2 + '@openzeppelin/contracts': 5.1.0 + '@openzeppelin/contracts-upgradeable': 5.1.0(@openzeppelin/contracts@5.1.0) + '@types/chai': 4.3.11 + '@types/mocha': 9.1.1 + '@types/node': 17.0.45 + chalk: 4.1.2 + cli-table: 0.3.11 + hardhat-gas-reporter: 1.0.9(hardhat@2.19.1(ts-node@10.9.1(@types/node@17.0.45)(typescript@5.3.2))(typescript@5.3.2)) + ts-node: 10.9.1(@types/node@17.0.45)(typescript@5.3.2) + typescript: 5.3.2 + transitivePeerDependencies: + - '@codechecks/client' + - '@swc/core' + - '@swc/wasm' + - bufferutil + - debug + - hardhat + - utf-8-validate + '@peersky/eth-auth@2.1.1': {} '@pkgr/core@0.1.1': {} diff --git a/src/multipass.ts b/src/multipass.ts index 98f5222..da5559d 100644 --- a/src/multipass.ts +++ b/src/multipass.ts @@ -2,22 +2,20 @@ import { ethers, Wallet } from "ethers"; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { LibMultipass } from "rankify-contracts/types/src/facets/DNSFacet"; import { RegisterMessage } from "./types"; +import { chainIdMapping, getArtifact, SupportedChains } from "./utils"; export default class Multipass { - // private JsonRpcProvider; - private chainId; - private name; - private version; - constructor({ chainId, contractName, version }: { chainId: any; contractName: string; version: string }) { - // if (!ProviderNetwork) throw new Error("Provider network not defined"); - // this.JsonRpcProvider = new ethers.providers.BaseProvider(ProviderNetwork); - this.chainId = chainId; - this.name = contractName; - this.version = version; + private chainId: string; + private name: string; + private version: string; + constructor({ chainName }: { chainName: SupportedChains }) { + this.chainId = chainIdMapping[chainName]; + const c = getArtifact(chainName, "Multipass"); + this.name = c.execute.args[0]; + this.version = c.execute.args[1]; } public getDappURL( message: any, signature: string, - // type: string, basepath: string, contractAddress: string, domain: string, @@ -34,6 +32,7 @@ export default class Multipass { this.chainId ); } + public signRegistrarMessage = async ( message: RegisterMessage, verifierAddress: string, @@ -64,7 +63,7 @@ export default class Multipass { }, { type: "uint256", - name: "deadline", + name: "validUntil", }, { type: "uint96", @@ -72,7 +71,7 @@ export default class Multipass { }, ], }; - + console.log("signing", domain, types, { ...message }); const s = await signer._signTypedData(domain, types, { ...message }); return s; }; @@ -92,7 +91,7 @@ export default class Multipass { name: ethers.utils.formatBytes32String(username), id: ethers.utils.formatBytes32String(id), domainName: ethers.utils.formatBytes32String(domainName), - deadline: ethers.BigNumber.from(validUntil), + validUntil: ethers.BigNumber.from(validUntil), nonce: ethers.BigNumber.from(0), }; diff --git a/src/types.ts b/src/types.ts index e9c5bc0..e12015f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,6 @@ import { BigNumber, Wallet, BytesLike } from "ethers"; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +export { LibMultipass } from "@peeramid-labs/multipass/types/src/Multipass"; export enum SearchCriteria { id, @@ -15,6 +16,6 @@ export interface RegisterMessage { name: BytesLike; id: BytesLike; domainName: BytesLike; - deadline: BigNumber; + validUntil: BigNumber; nonce: BigNumber; } diff --git a/src/utils/artifacts.ts b/src/utils/artifacts.ts index 411dc20..aae4f97 100644 --- a/src/utils/artifacts.ts +++ b/src/utils/artifacts.ts @@ -4,6 +4,11 @@ import { Rankify } from "rankify-contracts/types"; import { ethers } from "ethers"; export type SupportedChains = "anvil" | "localhost"; +export const chainIdMapping: { [key in SupportedChains]: string } = { + anvil: "97113", + localhost: "42161", +}; + export type ArtifactTypes = "Rankify" | "RankifyInstance" | "RankToken" | "Multipass"; /** * Retrieves the Rankify artifact for the specified chain. @@ -15,9 +20,11 @@ export type ArtifactTypes = "Rankify" | "RankifyInstance" | "RankToken" | "Multi export const getArtifact = ( chain: SupportedChains, artifactName: ArtifactTypes, -): { abi: JsonFragment[]; address: string } => { - const artifact = require(`rankify-contracts/deployments/${chain}/${artifactName}.json`); - +): { abi: JsonFragment[]; address: string; execute: { args: string[] } } => { + const artifact = + artifactName === "Multipass" + ? require(`@peeramid-labs/multipass/deployments/${chain}/${artifactName}.json`) + : require(`rankify-contracts/deployments/${chain}/${artifactName}.json`); if (!artifact) { throw new Error("Contract deployment not found"); }