-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9befb33
commit c076ed5
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as ecdh from 'crypto' | ||
import { getNet } from '@/lib/network' | ||
import { getActiveWallet } from '@/lib/wallet' | ||
import { AddressType, BaseWallet, ScriptType } from '@metalet/utxo-wallet-service' | ||
|
||
export async function process( | ||
_: unknown, | ||
{ path = "m/100'/0'/0'/0/0", externalPubKey }: { path?: string; externalPubKey: string } | ||
) { | ||
const network = getNet() | ||
const activeWallet = await getActiveWallet() | ||
|
||
const wallet = new BaseWallet({ | ||
// @ts-ignore | ||
path, | ||
network, | ||
addressIndex: 0, | ||
scriptType: ScriptType.P2PKH, | ||
mnemonic: activeWallet.mnemonic, | ||
addressType: AddressType.Legacy, | ||
}) | ||
|
||
const privateKey = wallet.getPrivateKeyBuffer() | ||
|
||
const _externalPubKey = Buffer.from(externalPubKey, 'hex') | ||
|
||
const ecdhKey = ecdh.createECDH('secp256k1') | ||
// @ts-ignore | ||
ecdhKey.setPrivateKey(privateKey) | ||
|
||
// 返回协商密钥 | ||
const sharedSecret = ecdhKey.computeSecret(_externalPubKey) | ||
|
||
return sharedSecret.toString('hex') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters