Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const steps = Array.isArray(claims) ? claims : [claims];
if (steps.some(x => x.authPrincipal)) {
// eslint-disable-next-line no-console
console.warn('Setting authPrincipal in claims object is not recommended, and may break things');
}
// Prepend auth principal claim by default
if (authPrincipal) {
let target = '';
let description = 'Please select authentication principal';
let chainInfo;
let targetType;
let declareParams;
if (typeof authPrincipal === 'string') {
if (isValidDid(authPrincipal)) {
// If auth principal is provided as a did
target = authPrincipal;
} else {
// If auth principal is provided as a string
description = authPrincipal;
}
}
if (typeof authPrincipal === 'object') {
target = get(authPrincipal, 'target', target);
description = get(authPrincipal, 'description', description);
targetType = get(authPrincipal, 'targetType', targetType);
declareParams = get(authPrincipal, 'declareParams', declareParams);
// If provided a chainInfo
if (authPrincipal.chainInfo && authenticator._isValidChainInfo(authPrincipal.chainInfo)) {
chainInfo = authPrincipal.chainInfo;
const sign = (signer, sk, payload = {}, doSign = true) => {
if (isValid(signer) === false) {
throw new Error('Cannot do sign with invalid signer');
}
const type = toTypeInfo(signer);
const headers = {
[types.KeyType.SECP256K1]: {
alg: 'ES256K',
type: 'JWT',
},
[types.KeyType.ED25519]: {
alg: 'Ed25519',
type: 'JWT',
},
};
// make header
client.finalizeConsumeAsset = ({ tx, address, delegator, wallet }, extra) => {
if (isValidDID(address) === false) {
throw new Error('Please provide valid asset address to consume');
}
return client.multiSignConsumeAssetTx(
{
tx,
wallet,
delegator,
data: {
typeUrl: 'fg:x:address',
value: Uint8Array.from(Buffer.from(address)),
},
},
extra
);
};