Skip to content

Commit

Permalink
Remove Wallet Selector Core (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Jun 22, 2024
1 parent e9e5735 commit 52045b7
Show file tree
Hide file tree
Showing 6 changed files with 461 additions and 581 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
"typescript": "^5.5.2"
},
"dependencies": {
"@near-wallet-selector/core": "^8.9.10",
"@walletconnect/web3wallet": "^1.12.3",
"elliptic": "^6.5.5",
"near-api-js": "^3.0.3",
"near-api-js": "^4.0.2",
"viem": "^2.16.1"
}
}
2 changes: 1 addition & 1 deletion src/chains/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class NearEthAdapter {
* @returns Near accountId linked to derived ETH.
*/
nearAccountId(): string {
return this.mpcContract.contract.account.accountId;
return this.mpcContract.connectedAccount.accountId;
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/chains/near.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { keyStores, KeyPair, connect, Account } from "near-api-js";
import { Wallet } from "@near-wallet-selector/core";

export const TGAS = 1000000000000n;
export const NO_DEPOSIT = "0";
Expand Down Expand Up @@ -57,16 +56,15 @@ export const nearAccountFromKeyPair = async (config: {
/** Minimally sufficient Account instance to construct the signing contract instance.
* Can't be used to change methods.
*/
export const nearAccountFromWallet = async (
wallet: Wallet,
export const nearAccountFromAccountId = async (
accountId: string,
network?: NearConfig
): Promise<Account> => {
const keyStore = new keyStores.InMemoryKeyStore();
const near = await connect({
...(network || TESTNET_CONFIG),
keyStore,
});
const accountId = (await wallet.getAccounts())[0].accountId;
const account = await near.account(accountId);
return account;
};
6 changes: 4 additions & 2 deletions src/mpcContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ interface MultichainContractInterface extends Contract {
*/
export class MultichainContract {
contract: MultichainContractInterface;
connectedAccount: Account;

constructor(account: Account, contractId: string) {
this.connectedAccount = account;
this.contract = new Contract(account, contractId, {
changeMethods: ["sign"],
viewMethods: ["public_key"],
Expand All @@ -58,7 +60,7 @@ export class MultichainContract {

const publicKey = await deriveChildPublicKey(
najPublicKeyStrToUncompressedHexPoint(rootPublicKey),
this.contract.account.accountId,
this.connectedAccount.accountId,
derivationPath
);

Expand All @@ -82,7 +84,7 @@ export class MultichainContract {
gas?: bigint
): NearContractFunctionPayload {
return {
signerId: this.contract.account.accountId,
signerId: this.connectedAccount.accountId,
receiverId: this.contract.contractId,
actions: [
{
Expand Down
16 changes: 15 additions & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { MultichainContract } from "../mpcContract";
import { FunctionCallAction } from "@near-wallet-selector/core";
// import { FunctionCallAction } from "@near-wallet-selector/core";
import { Hex, SignableMessage, TransactionSerializable } from "viem";

/**
* Borrowed from @near-wallet-selector/core
* https://github.com/near/wallet-selector/blob/01081aefaa3c96ded9f83a23ecf0d210a4b64590/packages/core/src/lib/wallet/transactions.types.ts#L12
*/
export interface FunctionCallAction {
type: "FunctionCall";
params: {
methodName: string;
args: object;
gas: string;
deposit: string;
};
}

export interface BaseTx {
/// Recipient of the transaction
to: `0x${string}`;
Expand Down
Loading

0 comments on commit 52045b7

Please sign in to comment.