Skip to content

Commit

Permalink
Lazy Setup (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Jul 30, 2024
1 parent d95f111 commit 7546451
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/chains/near.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const nearAccountFromAccountId = async (
return createNearAccount(accountId, network);
};

const createNearAccount = async (
export const createNearAccount = async (
accountId: string,
network: NearConfig,
keyPair?: KeyPair
Expand Down
27 changes: 27 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
import { KeyPair } from "near-api-js";
import { NearEthAdapter } from "./chains/ethereum";
import { MultichainContract } from "./mpcContract";
import { NearConfig } from "near-api-js/lib/near";
import { createNearAccount } from "./chains/near";

export * from "./chains/ethereum";
export * from "./chains/near";
export * from "./mpcContract";
export * from "./types/types";
export * from "./utils/signature";
export * from "./network";

interface SetupConfig {
accountId: string;
network: NearConfig;
privateKey?: string;
mpcContractId?: string;
derivationPath?: string;
}

export async function setupAdapter(args: SetupConfig): Promise<NearEthAdapter> {
const { privateKey, mpcContractId, derivationPath } = args;
const account = await createNearAccount(
args.accountId,
args.network,
privateKey ? KeyPair.fromString(privateKey) : undefined
);
return NearEthAdapter.fromConfig({
mpcContract: new MultichainContract(account, mpcContractId),
derivationPath: derivationPath || "ethereum,1",
});
}

0 comments on commit 7546451

Please sign in to comment.