-
Notifications
You must be signed in to change notification settings - Fork 7
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
cmd
committed
Jan 28, 2024
1 parent
d23c58f
commit ca4770a
Showing
20 changed files
with
385 additions
and
310 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
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
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
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
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,40 @@ | ||
import { parse_extkey } from '@cmdcode/crypto-tools/hd' | ||
import { verify_sig } from '@cmdcode/crypto-tools/signer' | ||
import { EscrowSigner } from '@/client/index.js' | ||
import { get_object_id } from '@/lib/util.js' | ||
|
||
import { | ||
get_deposit_address, | ||
get_deposit_ctx | ||
} from '@/lib/deposit.js' | ||
|
||
import { DepositAccount } from '@/types/index.js' | ||
|
||
import * as assert from '@/assert.js' | ||
|
||
export function verify_account ( | ||
account : DepositAccount, | ||
signer : EscrowSigner | ||
) { | ||
const { acct_id, acct_sig, ...rest } = account | ||
const { host_pub, network, pubkey } = signer | ||
|
||
const { | ||
address, agent_pk, deposit_pk, | ||
sequence, spend_xpub | ||
} = rest | ||
|
||
assert.ok(host_pub !== undefined, 'host pubkey is not set on device') | ||
assert.ok(pubkey === deposit_pk, 'deposit pubkey does not match device') | ||
assert.ok(signer.has_account(spend_xpub), 'account xpub is not recognized by master wallet') | ||
|
||
const return_pk = parse_extkey(spend_xpub).pubkey | ||
const context = get_deposit_ctx(agent_pk, deposit_pk, return_pk, sequence) | ||
const depo_addr = get_deposit_address(context, network) | ||
const digest = get_object_id(rest) | ||
|
||
assert.ok(address === depo_addr, 'account address does not match context') | ||
assert.ok(digest.hex === acct_id, 'account id does not match digest') | ||
|
||
verify_sig(acct_sig, acct_id, host_pub, { throws : true }) | ||
} |
Oops, something went wrong.