Skip to content

APE | 354 added key level in endorse token call and reverted getSigner functionality from temp commit b4534793b410ff5c86f173472794682376770c8a #359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@token-io/app",
"version": "1.0.40",
"version": "1.0.41",
"description": "Token JavaScript App SDK",
"license": "ISC",
"author": {
Expand Down
19 changes: 11 additions & 8 deletions app/src/http/AuthHttpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class AuthHttpClient extends CoreAuthHttpClient {
*/
async replaceToken(tokenToCancel, newResources) {
const cancelTokenId = tokenToCancel.id;
const cancelReq = await this._tokenOperationRequest(tokenToCancel, 'cancelled');
const cancelReq = await this._tokenOperationRequest(tokenToCancel, 'cancelled', config.KeyLevel.LOW);

const createReq = {
payload: {
Expand Down Expand Up @@ -439,11 +439,13 @@ class AuthHttpClient extends CoreAuthHttpClient {
* @param {Object} token - token to endorse
* @return {Object} response to the API call
*/
async endorseToken(token) {
async endorseToken(token, keyLevel) {
return this._tokenOperation(
token,
'endorse',
'endorsed');
'endorsed',
null,
keyLevel);
}

/**
Expand All @@ -458,7 +460,8 @@ class AuthHttpClient extends CoreAuthHttpClient {
token,
'cancel',
'cancelled',
blocking);
blocking,
config.KeyLevel.LOW);
}

/**
Expand Down Expand Up @@ -713,24 +716,24 @@ class AuthHttpClient extends CoreAuthHttpClient {
return this._instance(request);
}

async _tokenOperation(token, operation, suffix, blocking) {
async _tokenOperation(token, operation, suffix, blocking, keyLevel) {
const tokenId = token.id;
const request = {
method: 'put',
url: `/tokens/${tokenId}/${operation}`,
data: await this._tokenOperationRequest(token, suffix),
data: await this._tokenOperationRequest(token, suffix, keyLevel),
};
if (blocking) request.adapter = BlockingAdapter;
return this._instance(request);
}

async _tokenOperationRequest(token, suffix) {
async _tokenOperationRequest(token, suffix, keyLevel = config.KeyLevel.STANDARD) {
return {
tokenId: token.id,
signature: await this.tokenOperationSignature(
token.payload,
suffix,
config.KeyLevel.STANDARD),
keyLevel),
};
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/Member.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,13 @@ export default class Member extends CoreMember {
* the member prompting them to use a higher-privilege key.
*
* @param token - token to endorse, can be the token ID as well
* @param {string} keyLevel - 'LOW', 'STANDARD', or 'PRIVILEGED'
* @return endorsed token
*/
endorseToken(token: Token | string): Promise<TokenOperationResult> {
endorseToken(token: Token | string, keyLevel: string): Promise<TokenOperationResult> {
return Util.callAsync(this.endorseToken, async () => {
const finalToken = await this._resolveToken(token);
const endorsed = await this._client.endorseToken(finalToken);
const endorsed = await this._client.endorseToken(finalToken, keyLevel);
if (typeof token !== 'string') {
token.payloadSignatures = endorsed.data.result.token.payloadSignatures;
}
Expand Down
16 changes: 8 additions & 8 deletions core/src/http/AuthHttpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,30 @@ export class AuthHttpClient {

/**
* Creates the necessary signer objects, based on the level requested.
* If the level is not available, attempts to fetch a lower level.
* If the level is not available, attempts to fetch a higher level.
*
* @param {string} level - requested level of key
* @param {string} level - requested minimum level of key
* @return {Promise} object used to sign
*/
async getSigner(level) {
if (level === config.KeyLevel.LOW) {
return await this._cryptoEngine.createSigner(config.KeyLevel.LOW);
if (level === config.KeyLevel.PRIVILEGED) {
return await this._cryptoEngine.createSigner(config.KeyLevel.PRIVILEGED);
}
if (level === config.KeyLevel.STANDARD) {
try {
return await this._cryptoEngine.createSigner(config.KeyLevel.STANDARD);
} catch (err) {
return await this._cryptoEngine.createSigner(config.KeyLevel.LOW);
return await this._cryptoEngine.createSigner(config.KeyLevel.PRIVILEGED);
}
}
if (level === config.KeyLevel.PRIVILEGED) {
if (level === config.KeyLevel.LOW) {
try {
return await this._cryptoEngine.createSigner(config.KeyLevel.PRIVILEGED);
return await this._cryptoEngine.createSigner(config.KeyLevel.LOW);
} catch (err) {
try {
return await this._cryptoEngine.createSigner(config.KeyLevel.STANDARD);
} catch (err2) {
return await this._cryptoEngine.createSigner(config.KeyLevel.LOW);
return await this._cryptoEngine.createSigner(config.KeyLevel.PRIVILEGED);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tpp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tpp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@token-io/tpp",
"version": "1.0.49",
"version": "1.0.50",
"description": "Token JavaScript TPP SDK",
"license": "ISC",
"author": {
Expand Down
11 changes: 6 additions & 5 deletions tpp/src/http/AuthHttpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ class AuthHttpClient extends CoreAuthHttpClient {
return this._tokenOperation(
token,
'cancel',
'cancelled');
'cancelled',
config.KeyLevel.LOW);
}

/**
Expand Down Expand Up @@ -507,23 +508,23 @@ class AuthHttpClient extends CoreAuthHttpClient {
return this._instance(request);
}

async _tokenOperation(token, operation, suffix) {
async _tokenOperation(token, operation, suffix, keyLevel) {
const tokenId = token.id;
const request = {
method: 'put',
url: `/tokens/${tokenId}/${operation}`,
data: await this._tokenOperationRequest(token, suffix),
data: await this._tokenOperationRequest(token, suffix, keyLevel),
};
return this._instance(request);
}

async _tokenOperationRequest(token, suffix) {
async _tokenOperationRequest(token, suffix, keyLevel = config.KeyLevel.STANDARD) {
return {
tokenId: token.id,
signature: await this.tokenOperationSignature(
token.payload,
suffix,
config.KeyLevel.STANDARD),
keyLevel),
};
}
}
Expand Down