Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setClosedStellarURI(uri)
clearURI()
// Clear location href, since it might contain secret search params
window.history.pushState({}, "Solar Wallet", window.location.href.replace(window.location.search, ""))
},
[uri]
)
if (!renderedURI) {
return null
}
if (renderedURI.operation === StellarUriType.Transaction) {
if (isStellarGuardTransaction(renderedURI)) {
const transaction = new Transaction((renderedURI as TransactionStellarUri).xdr)
return (
<dialog open="{Boolean(uri)}">
</dialog>
)
}
} else if (renderedURI.operation === SolarUriType.Import) {
const secretKey = renderedURI.getParam("secret")
if (secretKey) {
return (
<dialog open="{Boolean(uri)}">
</dialog>
it('should fail to verify the wrong signature on a tx', co(function *() {
const keyPair = basecoin.generateKeyPair();
const tx = new stellar.Transaction(halfSignedTransaction.halfSigned.txBase64);
const validSignature = basecoin.verifySignature(keyPair.pub, tx.hash(), tx.signatures[0].signature());
validSignature.should.equal(false);
}));
function onRequest(payload) {
const tx = new StellarSdk.Transaction(payload.txenv);
const networkId = horizon.getNetworkId(payload.network);
const hash = multisig.getTransactionHash(tx, networkId);
payload.tx = tx;
addTransaction(hash, payload);
}
async signTransaction(tx: Transaction, account: Account, password: string): Promise {
let privateKey: string
try {
privateKey = keyStore.getPrivateKeyData(account.id, password).privateKey
} catch (error) {
throw WrongPasswordError()
}
const keypair = Keypair.fromSecret(privateKey)
const networkPassphrase = account.testnet ? Networks.TESTNET : Networks.PUBLIC
const signedTx = new Transaction((tx.toEnvelope().toXDR("base64") as unknown) as string, networkPassphrase)
signedTx.sign(keypair)
return signedTx
}
}
function deserializeTx(txResponse: ServerApi.TransactionRecord, testnet: boolean) {
const networkPassphrase = testnet ? Networks.TESTNET : Networks.PUBLIC
return Object.assign(new Transaction(txResponse.envelope_xdr, networkPassphrase), {
created_at: txResponse.created_at
})
}
expose(ipcMain, commands.signTransactionCommand, events.signTransactionEvent, function signTransaction(
txEnvelopeXdr,
keyID,
networkPassphrase,
password
) {
const transaction = new Transaction(txEnvelopeXdr, networkPassphrase)
let privateKey
try {
privateKey = keystore.getPrivateKeyData(keyID, password).privateKey
} catch (error) {
throw Object.assign(new Error("Wrong password."), { name: "WrongPasswordError" })
}
transaction.sign(Keypair.fromSecret(privateKey))
return transaction.toEnvelope().toXDR("base64")
})
async signTransaction(transaction: Transaction, account: Account, password: string) {
const transactionEnvelope = transaction.toEnvelope().toXDR("base64")
const event = await sendCommand(commands.keyStore.signTransactionCommand, {
keyID: account.id,
networkPassphrase: account.testnet ? networkPassphrases.testnet : networkPassphrases.mainnet,
password,
transactionEnvelope
})
if (event.data.error === "Wrong password") {
throw WrongPasswordError()
} else {
const signedTransactionEnvelope = event.data.result
const networkPassphrase = account.testnet ? Networks.TESTNET : Networks.PUBLIC
return new Transaction(signedTransactionEnvelope, networkPassphrase)
}
},
async removeKey(keyID: string) {
if (_.isUndefined(txPrebuild)) {
throw new Error('missing txPrebuild parameter');
}
if (!_.isObject(txPrebuild)) {
throw new Error(`txPrebuild must be an object, got type ${typeof txPrebuild}`);
}
if (_.isUndefined(prv)) {
throw new Error('missing prv parameter to sign transaction');
}
if (!_.isString(prv)) {
throw new Error(`prv must be a string, got type ${typeof prv}`);
}
const keyPair = stellar.Keypair.fromSecret(prv);
const tx = new stellar.Transaction(txPrebuild.txBase64);
tx.sign(keyPair);
return {
halfSigned: {
txBase64: Xlm.txToString(tx),
},
};
}