Socket
Socket
Sign inDemoInstall

@arianee/arianee-access-token

Package Overview
Dependencies
Maintainers
8
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arianee/arianee-access-token - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

2

package.json
{
"name": "@arianee/arianee-access-token",
"version": "0.3.1",
"version": "0.4.0",
"dependencies": {

@@ -5,0 +5,0 @@ "ethers": "6.3.0"

@@ -16,5 +16,12 @@ # @arianee/ArianeeAccessToken

### `createWalletAccessToken(): Promise<string>`
### `getValidWalletAccessToken(payloadOverride: PayloadOverride = {}, params?: { timeBeforeExp?: number; prefix?: string; }): Promise<string>`
This method generates a wallet scoped Arianee Access Token (AAT) and stores it in memory. On subsequent calls, if the stored AAT is still valid, it will return it. Otherwise if it has expired or the expiration is in less than `timeBeforeExp` seconds, it will regenerate a new one and return it.
You can use the `prefix` parameter to add a string before the arianee access token payload in the message to be signed.
### `createWalletAccessToken(payloadOverride: PayloadOverride = {}, prefix?: string): Promise<string>`
This method generates an Arianee Access Token (AAT) for the wallet scope. It returns a `Promise` that resolves to the AAT as a `string`.
It takes two optional parameters, a `payloadOverride` parameter to override the default payload and a `prefix` parameter to add a string before the arianee access token payload in the message to be signed.

@@ -33,3 +40,3 @@ ### `createCertificateArianeeAccessToken(certificateId: number, network: string): Promise<string>`

You can use the following static methods
You can use the following static methods. These methods will automatically detect if the arianee access token is prefixed and handle it. In order for this to work seamlessly, the arianee access tokens must be signed with one of these two signature algorithms (alg prop in header): `secp256k1` or `ETH`.

@@ -36,0 +43,0 @@ ### `static isArianeeAccessTokenValid(arianeeAccessToken: string): boolean`

@@ -12,4 +12,7 @@ import { Core } from '@arianee/core';

constructor(core: Core);
getValidWalletAccessToken(payloadOverride?: PayloadOverride, timeBeforeExp?: number): Promise<string>;
createWalletAccessToken(payloadOverride?: PayloadOverride): Promise<string>;
getValidWalletAccessToken(payloadOverride?: PayloadOverride, params?: {
timeBeforeExp?: number;
prefix?: string;
}): Promise<string>;
createWalletAccessToken(payloadOverride?: PayloadOverride, prefix?: string): Promise<string>;
createCertificateArianeeAccessToken(certificateId: number, network: string, payloadOverride?: PayloadOverride): Promise<string>;

@@ -16,0 +19,0 @@ createActionArianeeAccessTokenLink(url: string, certificateId: number, network: string): Promise<string>;

@@ -12,6 +12,7 @@ "use strict";

}
getValidWalletAccessToken(payloadOverride = {}, timeBeforeExp = 10) {
getValidWalletAccessToken(payloadOverride = {}, params) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const { timeBeforeExp = 10, prefix } = params !== null && params !== void 0 ? params : {};
if (!this.lastAAT || (0, timeBeforeExp_1.isExpInLessThan)(this.lastAAT, timeBeforeExp)) {
this.lastAAT = yield this.createWalletAccessToken(payloadOverride);
this.lastAAT = yield this.createWalletAccessToken(payloadOverride, prefix);
}

@@ -21,4 +22,4 @@ return this.lastAAT;

}
createWalletAccessToken(payloadOverride = {}) {
return this.generateAAT(payloadOverride);
createWalletAccessToken(payloadOverride = {}, prefix) {
return this.generateAAT(payloadOverride, prefix);
}

@@ -52,3 +53,3 @@ createCertificateArianeeAccessToken(certificateId, network, payloadOverride = {}) {

}
generateAAT(payload = {}) {
generateAAT(payload = {}, prefix) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {

@@ -62,3 +63,3 @@ const signer = (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {

const jwt = yield jwtGenerator.setPayload(basicPayload);
return jwt.sign();
return jwt.sign(prefix);
});

@@ -65,0 +66,0 @@ }

@@ -5,2 +5,4 @@ import { ArianeeAccessTokenPayload } from '../types/arianeeAccessTokenPayload';

private params;
private static readonly JWT_HEADER_ETH;
private static readonly JWT_HEADER_secp256k1;
private header;

@@ -29,2 +31,3 @@ private payload;

decode: () => {
prefix: string;
header: JwtHeaderInterface;

@@ -38,3 +41,3 @@ payload: ArianeeAccessTokenPayload;

private static fromBase64JSONParse;
sign(): Promise<string>;
sign(prefix?: string): Promise<string>;
/**

@@ -41,0 +44,0 @@ * Verify if signature was signed by pubKey and return true/false

@@ -58,12 +58,12 @@ "use strict";

static fromBase64JSONParse(data) {
const buffer = new Buffer(data, 'base64');
const buffer = Buffer.from(data, 'base64');
const string = buffer.toString('utf8');
return JSON.parse(string);
}
sign() {
sign(prefix) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const header = JWTGeneric.base64Stringified(this.header);
const payload = JWTGeneric.base64Stringified(this.payload);
const signature = yield this.signature();
return `${header}.${payload}.${signature}`;
const signature = yield this.signature(prefix !== null && prefix !== void 0 ? prefix : '');
return `${prefix !== null && prefix !== void 0 ? prefix : ''}${header}.${payload}.${signature}`;
});

@@ -79,7 +79,5 @@ }

}
const { header, signature, payload } = this.decode();
const joinedHeaderPayload = JWTGeneric.base64Stringified(header) +
'.' +
JWTGeneric.base64Stringified(payload);
const decode = this.params.recover(joinedHeaderPayload, signature);
const { prefix, header, payload, signature } = this.decode();
const signedMessage = `${prefix}${JWTGeneric.base64Stringified(header)}.${JWTGeneric.base64Stringified(payload)}`;
const decode = this.params.recover(signedMessage, signature);
const arePropertyValid = this.arePropertiesValid(payload, ignoreExpiration);

@@ -92,4 +90,9 @@ if (!arePropertyValid) {

decode() {
const [header, payload, signature] = this.encodedToken.split('.');
const headerType = this.encodedToken.includes(JWTGeneric.JWT_HEADER_ETH)
? JWTGeneric.JWT_HEADER_ETH
: JWTGeneric.JWT_HEADER_secp256k1;
const [prefix, remainder] = this.encodedToken.split(`${headerType}.`);
const [header, payload, signature] = [headerType, ...remainder.split('.')];
return {
prefix: prefix !== null && prefix !== void 0 ? prefix : '',
header: JWTGeneric.fromBase64JSONParse(header),

@@ -100,7 +103,8 @@ payload: JWTGeneric.fromBase64JSONParse(payload),

}
signature() {
signature(prefix) {
if (!this.params.signer) {
throw new Error('You must provide a signer');
}
return this.params.signer(JWTGeneric.base64Stringified(this.header) +
return this.params.signer(prefix +
JWTGeneric.base64Stringified(this.header) +
'.' +

@@ -111,2 +115,4 @@ JWTGeneric.base64Stringified(this.payload));

exports.JWTGeneric = JWTGeneric;
JWTGeneric.JWT_HEADER_ETH = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFVEgifQ==';
JWTGeneric.JWT_HEADER_secp256k1 = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJzZWNwMjU2azEifQ==';
//# sourceMappingURL=jwtGeneric.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc