Skip to content
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

Fix accounts REST API with DER encoded public key #2026

Merged
merged 3 commits into from
May 27, 2021
Merged
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
4 changes: 2 additions & 2 deletions hedera-mirror-rest/__tests__/ed25519.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ describe('Ed25519 tests', () => {
const validDecoded = '7a3c5477bdf4a63742647d7cfc4544acc1899d07141caf4cd9fea2f75b28a5cc';

let response = ed25519.derToEd25519(validDer);
expect(response).toEqual(validDecoded.toUpperCase()); // asn1js returns uppercase characters
expect(response).toEqual(validDecoded);

// Uppercase key
response = ed25519.derToEd25519(validDer.toUpperCase());
expect(response).toEqual(validDecoded.toUpperCase());
expect(response).toEqual(validDecoded);
});

test(`Inalid conversion:`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "Account api call for specific id with a matching public key",
"description": "Query accounts by public key and DER prefixed variations",
"setup": {
"accounts": [
{
Expand Down Expand Up @@ -59,7 +59,14 @@
"transactions": [],
"cryptotransfers": []
},
"url": "/api/v1/accounts?account.publickey=3c3d546321ff6f63d701d2ec5c277095874e19f4a235bee1e6bb19258bf362be",
"urls": [
Nana-EC marked this conversation as resolved.
Show resolved Hide resolved
"/api/v1/accounts?account.publickey=3c3d546321ff6f63d701d2ec5c277095874e19f4a235bee1e6bb19258bf362be",
"/api/v1/accounts?account.publickey=3C3D546321FF6F63D701D2EC5C277095874E19F4A235BEE1E6BB19258BF362BE",
"/api/v1/accounts?account.publickey=3c3D546321FF6F63D701D2EC5C277095874e19F4A235BEE1E6BB19258BF362be",
"/api/v1/accounts?account.publickey=302a300506032b65700321003c3d546321ff6f63d701d2ec5c277095874e19f4a235bee1e6bb19258bf362be",
"/api/v1/accounts?account.publickey=302A300506032B65700321003C3D546321FF6F63D701D2EC5C277095874E19F4A235BEE1E6BB19258BF362BE",
"/api/v1/accounts?account.publickey=302a300506032B65700321003C3D546321FF6F63D701D2EC5C277095874E19F4A235BEE1E6BB19258BF362be"
],
"responseStatus": 200,
"responseJson": {
"accounts": [
Expand Down
4 changes: 2 additions & 2 deletions hedera-mirror-rest/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('utils encodeMessage tests', () => {

test(`Verify parsePublicKey on valid decode publickey`, () => {
const validDer = '302a300506032b65700321007a3c5477bdf4a63742647d7cfc4544acc1899d07141caf4cd9fea2f75b28a5cc';
const validDecoded = '7A3C5477BDF4A63742647D7CFC4544ACC1899D07141CAF4CD9FEA2F75B28A5CC';
const validDecoded = '7a3c5477bdf4a63742647d7cfc4544acc1899d07141caf4cd9fea2f75b28a5cc';
expect(utils.parsePublicKey(validDer)).toBe(validDecoded);
});
});
Expand Down Expand Up @@ -576,7 +576,7 @@ describe('Utils parsePublicKeyQueryParam tests', () => {
'gte:302a300506032b65700321007a3c5477bdf4a63742647d7cfc4544acc1899d07141caf4cd9fea2f75b28a5cc',
},
expectedClause: 'account.publickey >= ?',
expectedValues: ['7A3C5477BDF4A63742647D7CFC4544ACC1899D07141CAF4CD9FEA2F75B28A5CC'],
expectedValues: ['7a3c5477bdf4a63742647d7cfc4544acc1899d07141caf4cd9fea2f75b28a5cc'],
},
];
parseQueryParamTest('Utils parsePublicKeyQueryParam - ', testSpecs, (spec) =>
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-rest/ed25519.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const derToEd25519 = function (der) {
const {valueBlock} = asn1Result.valueBlock.value[0].valueBlock.value[0];
if (valueBlock.blockName == 'ObjectIdentifierValueBlock' && valueBlock.value == ID_Ed25519) {
const ed25519Key = asn1Result.valueBlock.value[1].valueBlock.valueHex;
return ed25519Key;
return ed25519Key.toLowerCase();
}
return null;
} catch (err) {
Expand Down