-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
fs
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Near, NearConfig } from './near'; | ||
|
||
export type ConnectConfig = NearConfig & { | ||
keyPath?: string; | ||
} | ||
|
||
/** | ||
* Initialize connection to Near network. | ||
*/ | ||
export async function connect(config: ConnectConfig): Promise<Near> { | ||
return new Near(config); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * as keyStores from './key_stores/browser-index'; | ||
export * from './common-index'; | ||
export * from './browser-connect'; | ||
|
||
import 'error-polyfill'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { readKeyFile } from './key_stores/unencrypted_file_system_keystore'; | ||
import { InMemoryKeyStore, MergeKeyStore } from './key_stores'; | ||
import { Near, NearConfig } from './near'; | ||
|
||
export type ConnectConfig = NearConfig & { | ||
keyPath?: string; | ||
} | ||
|
||
/** | ||
* Initialize connection to Near network. | ||
*/ | ||
export async function connect(config: ConnectConfig): Promise<Near> { | ||
// Try to find extra key in `KeyPath` if provided. | ||
if (config.keyPath && config.deps && config.deps.keyStore) { | ||
try { | ||
const accountKeyFile = await readKeyFile(config.keyPath); | ||
if (accountKeyFile[0]) { | ||
// TODO: Only load key if network ID matches | ||
const keyPair = accountKeyFile[1]; | ||
const keyPathStore = new InMemoryKeyStore(); | ||
await keyPathStore.setKey(config.networkId, accountKeyFile[0], keyPair); | ||
if (!config.masterAccount) { | ||
config.masterAccount = accountKeyFile[0]; | ||
} | ||
config.deps.keyStore = new MergeKeyStore([config.deps.keyStore, keyPathStore]); | ||
console.log(`Loaded master account ${accountKeyFile[0]} key from ${config.keyPath} with public key = ${keyPair.getPublicKey()}`); | ||
} | ||
} catch (error) { | ||
console.warn(`Failed to load master account key from ${config.keyPath}: ${error}`); | ||
} | ||
} | ||
return new Near(config); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * as keyStores from './key_stores/index'; | ||
export * from './common-index'; | ||
export * from './common-index'; | ||
export * from './connect'; |