0

Here:

var privateKeys = [...];
var sp = new JsSignatureProvider(privateKeys);
var key = 'ASG...';
sp.addKey(key);  // (1)

I want to add new key to JsSignatureProvider, but I can't find method like (1). Is it exists?

How can we add new key to JsSignatureProvider after it already been constructed?

Thank you!

ps. We don't use JsSignatureProvider in production code. Just for testing.

1

You need to add public key to JsSignatureProvider.availableKeys (string[]) and private key to JsSignatureProvider.keys (Map<string,string>) by public key.

var { Numeric } = require('eosjs');
var { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig');
var ecc = require('eosjs-ecc');

var privateKeys = ['...'];
var sp = new JsSignatureProvider(privateKeys);
var key ='...';

const pub = Numeric.convertLegacyPublicKey(ecc.PrivateKey.fromString(key).toPublic().toString());
sp.keys.set(pub, key);
sp.availableKeys.push(pub);
| improve this answer | |
  • Didn't know about 'Numeric.convertLegacyPublicKey' method. Thank you! – Teresa May 1 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.