Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (transfer.executionCondition === MESSAGE_STRING) {
this._handleLedgerMessage(transfer)
break
}
// check that the incoming transfer is locked with the right control program
await escrow.verify({
utxo: output,
client: this._client,
sourceReceiver: output.referenceData.sourceReceiver,
destinationPubkey: this._key.pubkey,
amount: output.amount,
assetId: output.assetId,
// TODO decide on which part of the codebase is dealing with which date format
expiresAt: moment(output.referenceData.expiresAt).valueOf(),
condition: base64url.decode(output.referenceData.executionCondition, 'hex')
})
// TODO check that all the referenceData we expect is there
debug('emitting incoming_prepare', transfer)
try {
this._safeEmit('incoming_prepare', transfer)
} catch (err) {
console.error('error in event handler', err)
}
} else if (this._outputIsFromUs(output)) {
const transfer = this._parseTransferFromOutput(output)
this._safeEmit('outgoing_prepare', transfer)
}
}
}
console.log('Got access token: %s', access_token);
if (body.refresh_token) {
refresh_token = body.refresh_token;
console.log('Got refresh token: %s', refresh_token);
}
if (body.id_token) {
console.log('Got ID token: %s', body.id_token);
// check the id token
var pubKey = jose.KEYUTIL.getKey(rsaKey);
var signatureValid = jose.jws.JWS.verify(body.id_token, pubKey, ['RS256']);
if (signatureValid) {
console.log('Signature validated.');
var tokenParts = body.id_token.split('.');
var payload = JSON.parse(base64url.decode(tokenParts[1]));
console.log('Payload', payload);
if (payload.iss == 'http://localhost:9001/') {
console.log('issuer OK');
if ((Array.isArray(payload.aud) && _.contains(payload.aud, client.client_id)) ||
payload.aud == client.client_id) {
console.log('Audience OK');
var now = Math.floor(Date.now() / 1000);
if (payload.iat <= now) {
console.log('issued-at OK');
if (payload.exp >= now) {
console.log('expiration OK');
console.log('Token valid!');
export function decodeToken(token: string | TokenInterface): TokenInterface {
if (typeof token === 'string') {
// decompose the token into parts
const tokenParts = token.split('.')
const header = JSON.parse(base64url.decode(tokenParts[0]))
const payload = JSON.parse(base64url.decode(tokenParts[1]))
const signature = tokenParts[2]
// return the token object
return {
header: header,
payload: payload,
signature: signature
}
} else if (typeof token === 'object') {
if (typeof token.payload !== 'string') {
throw new Error('Expected token payload to be a base64 or json string')
}
let payload = token.payload
if (token.payload[0] !== '{') {
payload = base64url.decode(payload)
/****************************************************************************
* JWE compact format structure
****************************************************************************
* BASE64URL(UTF8(JWE Protected Header)) || '.' ||
* BASE64URL(JWE Encrypted Key) || '.' ||
* BASE64URL(JWE Initialization Vector) || '.' ||
* BASE64URL(JWE Ciphertext) || '.' ||
* BASE64URL(JWE Authentication Tag)
***************************************************************************/
var parts = jweString.split('.');
if (parts.length !== 5)
return callback(new Error('In jwe.decrypt: invalid JWE string, it has ' + parts.length + ' parts instead of 5'), null);
var header;
try {
header = JSON.parse(base64url.decode(parts[0], 'binary'));
} catch (ex) {
return callback(new Error('In jwe.decrypt: failed to parse JWE header'), null);
}
var aad = createBuffer(parts[0]);
var encrypted_cek = base64url.toBuffer(parts[1]);
var iv = base64url.toBuffer(parts[2]);
var cipherText = base64url.toBuffer(parts[3]);
var authTag = base64url.toBuffer(parts[4]);
log.info('In jwe.decrypt: the header is ' + JSON.stringify(header));
var cek_result;
var content_result;
// special treatment of 'dir'
let ExtendedJWT = this
let protectedHeader, payload, signature
// Parse
if (typeof data === 'string') {
let segments = data.split('.')
if (![3, 5].includes(segments.length)) {
throw new DataError('Malformed JWT')
}
// Decode base64url
if (segments.length === 3) {
try {
protectedHeader = JSON.parse(base64url.decode(segments[0]))
payload = JSON.parse(base64url.decode(segments[1]))
signature = segments[2]
} catch (err) {
throw new DataError('Malformed JWS')
}
}
if (segments.length === 5) {
// TODO JWE
}
}
// Sanity Check
if (typeof protectedHeader !== 'object' || protectedHeader === null || Array.isArray(protectedHeader)) {
throw new DataError('JWT Header must be an object')
}
}
}
// Input should be an object by now
if (typeof data !== 'object' || data === null || Array.isArray(data)) {
throw new DataError('Invalid JWT')
}
// Signatures must be present and an array
if (!Array.isArray(data.signatures)) {
throw new DataError('JWT signatures property must be an array')
}
// Decode payload
try {
payload = JSON.parse(base64url.decode(data.payload))
} catch (err) {
throw new Error('Invalid JWT')
}
// Decode signatures
signatures = data.signatures.map(descriptor => {
let { protected: protectedHeader, header: unprotectedHeader, signature } = descriptor
let decodedHeader
try {
decodedHeader = JSON.parse(base64url.decode(protectedHeader))
} catch (err) {
throw new DataError('Invalid JWT')
}
if (!decodedHeader || typeof decodedHeader !== 'object' || decodedHeader === null || Array.isArray(decodedHeader)) {
const operations = batchFile.operations.map((encodedOp) => {
const operationHash = base64url.encode(
crypto
.createHash('sha256')
.update(base64url.toBuffer(encodedOp))
.digest(),
);
const decodedOperation = JSON.parse(base64url.decode(encodedOp));
const decodedOperationPayload = JSON.parse(base64url.decode(decodedOperation.payload));
return {
operationHash,
transaction: txn,
decodedOperation,
decodedOperationPayload,
};
});
function decodeState (state) {
try {
return JSON.parse(base64url.decode(state))
} catch (err) {
return {}
}
}
Redsys.prototype.merchantSignatureIsValid = function (signA, signB){
return base64url.decode(signA,'base64')==base64url.decode(signB,'base64');
}