-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
authenticated remote signer requests #1985
Open
e-asphyx
wants to merge
6
commits into
master
Choose a base branch
from
remote-signer-auth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
28d97f2
authenticated remote signer requests
e-asphyx 73aac8f
Merge remote-tracking branch 'origin/master' into remote-signer-auth
e-asphyx e48ae1e
revert package locks
e-asphyx bf745b6
revert package locks 2
e-asphyx 7ff8ed9
taquito-remote-signer README updated
e-asphyx 5521bcc
arguments renamed
e-asphyx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { checkDecodeTezosID, encodeTezosID } from '@taquito/michel-codec'; | ||
import * as ed25519 from '@stablelib/ed25519'; | ||
import * as blake2b from '@stablelib/blake2b'; | ||
import elliptic from 'elliptic'; | ||
import { TezosIDType } from '@taquito/michel-codec'; | ||
|
||
enum PublicKeyHashID { | ||
ED25519 = 0, | ||
SECP256K1 = 1, | ||
P256 = 2, | ||
} | ||
|
||
function computeDigest(msg: Uint8Array, pkh: [TezosIDType, number[]]): Uint8Array { | ||
const hashType = pkh[0] == 'ED25519PublicKeyHash' ? PublicKeyHashID.ED25519 : | ||
pkh[0] == 'SECP256K1PublicKeyHash' ? PublicKeyHashID.SECP256K1 : | ||
PublicKeyHashID.P256; | ||
|
||
const buf = new Uint8Array(msg.length + pkh[1].length + 3); | ||
buf.set([4, 1, hashType]); | ||
buf.set(pkh[1], 3); | ||
buf.set(msg, 3+pkh[1].length); | ||
return blake2b.hash(buf, 32); | ||
} | ||
|
||
export function authenticateRequest(msg: Uint8Array, secretKey: string, pkh: string): string { | ||
const tmp = checkDecodeTezosID(secretKey, 'ED25519Seed', 'P256SecretKey', 'SECP256K1SecretKey'); | ||
if (tmp == null) { | ||
throw new Error('invalid private key format'); | ||
} | ||
const [t, secret] = tmp; | ||
const pubHash = checkDecodeTezosID(pkh, 'ED25519PublicKeyHash', 'P256PublicKeyHash', 'SECP256K1PublicKeyHash'); | ||
if (pubHash == null) { | ||
throw new Error('invalid public key hash format'); | ||
} | ||
const secData = new Uint8Array(secret); | ||
const digest = computeDigest(msg, pubHash); | ||
let signature: Uint8Array; | ||
let sigType: TezosIDType; | ||
if (t == 'ED25519Seed') { | ||
const kp = ed25519.generateKeyPairFromSeed(secData); | ||
signature = ed25519.sign(kp.secretKey, digest); | ||
sigType = 'ED25519Signature'; | ||
} else { | ||
const kp = new elliptic.ec(t == 'SECP256K1SecretKey' ? 'secp256k1' : 'p256').keyFromPrivate(secData); | ||
const sig = kp.sign(digest); | ||
const r = sig.r.toArray(); | ||
const s = sig.s.toArray(); | ||
signature = new Uint8Array(64); | ||
signature.set(r, 32-r.length); | ||
signature.set(s, 64-s.length); | ||
sigType = t == 'SECP256K1SecretKey' ? 'SECP256K1Signature' : 'P256Signature'; | ||
} | ||
return encodeTezosID(sigType, signature); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could specify "The secret key shouldn't be associated with an onchain account"