Skip to content

Commit

Permalink
Merge pull request #324 from docknetwork/feat/key-type-detection
Browse files Browse the repository at this point in the history
Fix key type detection if pair has type field
  • Loading branch information
cykoder authored Nov 5, 2022
2 parents 03ef36d + 1905625 commit 83ddc70
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/sdk",
"version": "2.6.0",
"version": "2.6.1",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ export function verifyEcdsaSecp256k1SigPrehashed(messageHash, signature, publicK
/**
* Return the type of signature from a given keypair
* @param {object} pair - Can be a keypair from polkadot-js or elliptic library.
* @returns {string|*} For now, it can be ed25519 or sr25519 or secp256k1 or an error
* @returns {string|*}
*/
export function getKeyPairType(pair) {
if (pair.type && (pair.type === 'ed25519' || pair.type === 'sr25519')) {
// Polkadot-js keyring has type field with value either 'ed25519' or 'sr25519'
if (pair.type) {
return pair.type;
}

if (pair.ec && pair.priv) {
// elliptic library's pair has `ec`, `priv` and `pub`. There is not a cleaner way to detect that
return 'secp256k1';
}
throw new Error('Only ed25519, sr25519 and secp256k1 keys supported as of now');
throw new Error('Cannot detect key pair type');
}

/**
Expand Down

0 comments on commit 83ddc70

Please sign in to comment.