Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pathname = '',
extraParams = {},
}) {
this._verifyClaims(verifiableClaims);
this._verifyAuthorizer(authorizer);
this._validateAppInfo(appInfo, { address: authorizer.did });
const claimsInfo = await this.genRequestedClaims({ claims, context, extraParams });
const chainInfoParams = Object.assign({}, context, extraParams);
// FIXME: this maybe buggy if user provided multiple claims
const tmp = claimsInfo.find(x => this.getChainInfo(chainInfoParams, x.chainInfo || {}));
const payload = {
action: 'responseAuth',
appInfo,
iss: toDid(authorizer.did),
agentDid: toDid(this.wallet.address),
chainInfo: this.getChainInfo(chainInfoParams, tmp ? tmp.chainInfo : undefined),
verifiableClaims,
requestedClaims: claimsInfo.map(x => {
delete x.chainInfo;
return x;
}),
url: `${this.baseUrl}${pathname}?${qs.stringify(Object.assign({ [this.tokenKey]: token }, extraParams))}`,
};
const signed = {
appPk: toBase58(authorizer.pk),
agentPk: this.appPk,
authInfo: Jwt.sign(this.wallet.address, this.wallet.sk, payload),
};
extraParams = {},
}) {
this._verifyClaims(verifiableClaims);
this._verifyAuthorizer(authorizer);
this._validateAppInfo(appInfo, { address: authorizer.did });
const claimsInfo = await this.genRequestedClaims({ claims, context, extraParams });
const chainInfoParams = Object.assign({}, context, extraParams);
// FIXME: this maybe buggy if user provided multiple claims
const tmp = claimsInfo.find(x => this.getChainInfo(chainInfoParams, x.chainInfo || {}));
const payload = {
action: 'responseAuth',
appInfo,
iss: toDid(authorizer.did),
agentDid: toDid(this.wallet.address),
chainInfo: this.getChainInfo(chainInfoParams, tmp ? tmp.chainInfo : undefined),
verifiableClaims,
requestedClaims: claimsInfo.map(x => {
delete x.chainInfo;
return x;
}),
url: `${this.baseUrl}${pathname}?${qs.stringify(Object.assign({ [this.tokenKey]: token }, extraParams))}`,
};
const signed = {
appPk: toBase58(authorizer.pk),
agentPk: this.appPk,
authInfo: Jwt.sign(this.wallet.address, this.wallet.sk, payload),
};
debug('responseAuth.sign', { context, extraParams, payload, signed });
},
[types.KeyType.ED25519]: {
alg: 'Ed25519',
type: 'JWT',
},
};
// make header
const header = headers[type.pk];
const headerB64 = toBase64(stringify(header));
// make body
const now = Math.floor(Date.now() / 1000);
let body = Object.assign(
{
iss: toDid(signer),
iat: now,
nbf: now,
exp: now + 5 * 60,
version: DID_AUTH_PROTOCOL_VERSION,
},
payload || {}
);
// remove empty keys
body = Object.keys(body)
.filter(x => {
if (typeof body[x] === 'undefined' || body[x] == null || body[x] === '') {
return false;
}
return true;
})
function toStakeDid(sender, receiver) {
toDid(toStakeAddress(sender, receiver));
}
function toItxDid(itx, type) {
return toDid(toItxAddress(itx, type));
}
sign(payload) {
const { pk, sk, address } = this.wallet;
return {
appPk: toBase58(pk),
appInfo: JWT.sign(toDid(address), sk, payload),
};
}
function toAssetDid(itx) {
return toDid(toAssetAddress(itx));
}