Skip to content

Commit

Permalink
Added multipass dependency and made necessary changes (#29)
Browse files Browse the repository at this point in the history
* WIP: added multipass dependecie and made few changes

* init

* add execute to artifact return type

* applied formatting

* Add multipass API support and update related types

* Update dirty-pillows-hear.md

---------

Co-authored-by: theKosmoss <[email protected]>
Co-authored-by: Tim Pechersky <[email protected]>
Co-authored-by: Peersky <[email protected]>
  • Loading branch information
4 people authored Nov 13, 2024
1 parent 410fb41 commit 1270766
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-pillows-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rankify-js": minor
---

Added changes needed to support multipass as stanadlone package
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 13 additions & 14 deletions src/multipass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -34,6 +32,7 @@ export default class Multipass {
this.chainId
);
}

public signRegistrarMessage = async (
message: RegisterMessage,
verifierAddress: string,
Expand Down Expand Up @@ -64,15 +63,15 @@ export default class Multipass {
},
{
type: "uint256",
name: "deadline",
name: "validUntil",
},
{
type: "uint96",
name: "nonce",
},
],
};

console.log("signing", domain, types, { ...message });
const s = await signer._signTypedData(domain, types, { ...message });
return s;
};
Expand All @@ -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),
};

Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -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";

Check failure on line 3 in src/types.ts

View workflow job for this annotation

GitHub Actions / release

Cannot find module '@peeramid-labs/multipass/types/src/Multipass' or its corresponding type declarations.

export enum SearchCriteria {
id,
Expand All @@ -15,6 +16,6 @@ export interface RegisterMessage {
name: BytesLike;
id: BytesLike;
domainName: BytesLike;
deadline: BigNumber;
validUntil: BigNumber;
nonce: BigNumber;
}
13 changes: 10 additions & 3 deletions src/utils/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");
}
Expand Down

0 comments on commit 1270766

Please sign in to comment.