Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(params: DataProviderParams) {
const accountKey = isAccount(params.accountOrKey)
? params.accountOrKey.publicKey
: params.accountOrKey;
if (!accountKey) {
throw new Error("No account key provided.");
}
if (!params.serverUrl) {
throw new Error("No server url provided.");
}
// make sure the account key is a real account
try {
Keypair.fromPublicKey(accountKey);
} catch (e) {
throw new Error(`The provided key was not valid: ${accountKey}`);
}
this.callbacks = {};
this.errorHandlers = {};
this.serverUrl = params.serverUrl;
this.server = new Server(this.serverUrl);
this.accountKey = accountKey;
this._watcherTimeouts = {};
}
async _signTe(teSignatureBaseSerialized) {
this.assertState(HWW_STATE.READY);
const signatureWrapper = await this.str.signTransaction(`44'/${HardwareWalletLedger.bip44}'/${this.subaccount}'`, Buffer.from(teSignatureBaseSerialized, 'base64'));
// add signature to transaction
const keyPair = Keypair.fromPublicKey(this.publicKey);
const hint = keyPair.signatureHint();
const decoratedSignature = new xdr.DecoratedSignature({hint: hint, signature: signatureWrapper.signature});
return decoratedSignature.toXDR().toString('base64');
}
export function signatureMatchesPublicKey(signature: xdr.DecoratedSignature, publicKey: string): boolean {
const keypair = Keypair.fromPublicKey(publicKey)
return signature.hint().equals(keypair.signatureHint())
}
return transaction.signatures.some(signature => {
const hint = signature.hint()
const keypair = Keypair.fromPublicKey(publicKey)
return hint.equals(keypair.rawPublicKey().slice(-hint.byteLength))
})
}