Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
): Promise {
const withoutAttestation = await createAuthenticatorDataWithoutAttestation(rpId, counter);
const aaguid = KRYPTON_AAGUID;
const credIdLen = new Uint8Array(2);
credIdLen[0] = (credId.length >> 8) & 0xff;
credIdLen[1] = credId.length & 0xff;
const attData = new Map();
attData.set(1, 2);
attData.set(3, -7);
attData.set(-1, 1);
attData.set(-2, new Buffer(publicKey.slice(1, 33).buffer)); // x-coord
attData.set(-3, new Buffer(publicKey.slice(33, 65).buffer)); // y-coord
const attCBOR = new Uint8Array(CBOR.encodeCanonical(attData));
const authenticatorData = new Uint8Array( withoutAttestation.length
+ aaguid.length
+ credIdLen.byteLength
+ credId.length + attCBOR.byteLength);
let offset = 0;
authenticatorData.set(withoutAttestation, offset);
offset += withoutAttestation.length;
authenticatorData.set(aaguid, offset);
offset += aaguid.length;
authenticatorData.set(credIdLen, offset);
offset += credIdLen.byteLength;
throw new Error('no u2f_register_response');
}
if (response.u2f_register_response.error) {
throw response.u2f_register_response.error;
}
const u2fRegisterResponse = response.u2f_register_response;
const authenticatorData = await createAuthenticatorDataWithAttestation(rpId,
u2fRegisterResponse.counter,
u2fRegisterResponse.key_handle,
u2fRegisterResponse.public_key);
let attestationObject: ArrayBuffer;
if (pkOptions.attestation == null || pkOptions.attestation === 'none') {
attestationObject = CBOR.encodeCanonical({
attStmt: {},
authData: new Buffer(authenticatorData.buffer),
fmt: 'none',
}).buffer;
} else {
attestationObject = CBOR.encodeCanonical({
attStmt: {
sig: new Buffer(u2fRegisterResponse.signature.buffer),
x5c: [new Buffer(u2fRegisterResponse.attestation_certificate.buffer)],
},
authData: new Buffer(authenticatorData.buffer),
fmt: 'fido-u2f',
}).buffer;
}
const credential: Credential = {
}
const txOutputs = fullOutputs[inputTxId]
if (!txOutputs) {
throw new Error(`No UTxO is found for tx ${inputTxId}! Maybe the blockchain is still syncing? If not - something is wrong.`)
}
const { address: inputAddress, amount: inputAmount } = txOutputs[inputIdx]
this.logger.debug(`Validating witness for input: ${inputTxId}.${inputIdx} (${inputAmount} coin from ${inputAddress})`)
const { addressRoot, addrAttr, addressType } = ByronValidator.deconstructAddress(inputAddress)
if (addressType !== 0) {
this.logger.debug(`Unsupported address type: ${addressType}. Skipping witness validation for this input.`)
return
}
const addressRootHex = addressRoot.toString('hex')
const expectedStruct = [0, [0, sign[0]], addrAttr]
const encodedStruct = Buffer.from(sha3_256.update(
cbor.encodeCanonical(expectedStruct)).digest())
const expectedRootHex = blake.blake2bHex(encodedStruct, undefined, 28)
if (addressRootHex !== expectedRootHex) {
throw new Error(`Witness does not match! ${JSON.stringify({ addressRootHex, expectedRoot: expectedRootHex })}`)
}
})
}
}
const { address: inputAddress, amount: inputAmount } = txOutputs[inputIdx]
this.logger.debug(`Validating witness for input: ${inputTxId}.${inputIdx} (${inputAmount} coin from ${inputAddress})`)
const {
addressRoot,
addrAttr,
addressType,
} = ShelleyValidator.deconstructAddress(inputAddress)
if (addressType !== 0) {
this.logger.debug(`Unsupported address type: ${addressType}. Skipping witness validation for this input.`)
return
}
const addressRootHex = addressRoot.toString('hex')
const expectedStruct = [0, [0, sign[0]], addrAttr]
const encodedStruct = Buffer.from(sha3_256.update(
cbor.encodeCanonical(expectedStruct)).digest())
const expectedRootHex = blake.blake2bHex(encodedStruct, undefined, 28)
if (addressRootHex !== expectedRootHex) {
throw new Error(`Witness does not match! ${JSON.stringify({ addressRootHex, expectedRoot: expectedRootHex })}`)
}
})
}