Skip to content

Commit 7546451

Browse files
authored
Lazy Setup (#84)
1 parent d95f111 commit 7546451

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/chains/near.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const nearAccountFromAccountId = async (
3535
return createNearAccount(accountId, network);
3636
};
3737

38-
const createNearAccount = async (
38+
export const createNearAccount = async (
3939
accountId: string,
4040
network: NearConfig,
4141
keyPair?: KeyPair

src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1+
import { KeyPair } from "near-api-js";
2+
import { NearEthAdapter } from "./chains/ethereum";
3+
import { MultichainContract } from "./mpcContract";
4+
import { NearConfig } from "near-api-js/lib/near";
5+
import { createNearAccount } from "./chains/near";
6+
17
export * from "./chains/ethereum";
28
export * from "./chains/near";
39
export * from "./mpcContract";
410
export * from "./types/types";
511
export * from "./utils/signature";
612
export * from "./network";
13+
14+
interface SetupConfig {
15+
accountId: string;
16+
network: NearConfig;
17+
privateKey?: string;
18+
mpcContractId?: string;
19+
derivationPath?: string;
20+
}
21+
22+
export async function setupAdapter(args: SetupConfig): Promise<NearEthAdapter> {
23+
const { privateKey, mpcContractId, derivationPath } = args;
24+
const account = await createNearAccount(
25+
args.accountId,
26+
args.network,
27+
privateKey ? KeyPair.fromString(privateKey) : undefined
28+
);
29+
return NearEthAdapter.fromConfig({
30+
mpcContract: new MultichainContract(account, mpcContractId),
31+
derivationPath: derivationPath || "ethereum,1",
32+
});
33+
}

0 commit comments

Comments
 (0)