forked from trent_larson/crowd-funder-for-time-pwa
change accessToken to take a DID
This commit is contained in:
@@ -86,43 +86,21 @@ export const generateSeed = (): string => {
|
||||
/**
|
||||
* Retreive an access token
|
||||
*
|
||||
* @param {IIdentifier} identifier
|
||||
* @return {*}
|
||||
*/
|
||||
export const accessToken = async (
|
||||
identifier: IIdentifier | undefined,
|
||||
did?: string,
|
||||
) => {
|
||||
export const accessToken = async (did?: string) => {
|
||||
if (did) {
|
||||
const nowEpoch = Math.floor(Date.now() / 1000);
|
||||
const endEpoch = nowEpoch + 60; // add one minute
|
||||
const tokenPayload = { exp: endEpoch, iat: nowEpoch, iss: did };
|
||||
return createEndorserJwt(did, tokenPayload);
|
||||
} else {
|
||||
// deprecated
|
||||
// must have identifier
|
||||
const did = identifier?.did;
|
||||
const privateKeyHex: string = identifier?.keys[0].privateKeyHex as string;
|
||||
|
||||
const signer = SimpleSigner(privateKeyHex);
|
||||
|
||||
const nowEpoch = Math.floor(Date.now() / 1000);
|
||||
const endEpoch = nowEpoch + 60; // add one minute
|
||||
|
||||
const tokenPayload = { exp: endEpoch, iat: nowEpoch, iss: did };
|
||||
const alg = undefined; // defaults to 'ES256K', more standardized but harder to verify vs ES256K-R
|
||||
const jwt: string = await didJwt.createJWT(tokenPayload, {
|
||||
alg,
|
||||
issuer: did || "no DID set",
|
||||
signer,
|
||||
});
|
||||
return jwt;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const sign = async (privateKeyHex: string) => {
|
||||
const signer = SimpleSigner(privateKeyHex);
|
||||
|
||||
return signer;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user