From 4eb490f84b84ee72f1e29de8fc7aae110500927e Mon Sep 17 00:00:00 2001 From: Dincho Todorov Date: Mon, 4 Nov 2024 12:47:28 +0200 Subject: [PATCH] Add support for account_seckey in API encoder (#292) --- README.md | 1 + src/ApiEncoder.js | 2 ++ tests/ApiEncoder.js | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ea5b4341..cf0cf07b 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,7 @@ Any of the following FATE API data types can be encoded and decoded: - contract_bytearray - contract_pubkey - account_pubkey +- account_seckey - channel - oracle_pubkey - oracle_query_id diff --git a/src/ApiEncoder.js b/src/ApiEncoder.js index 4f59fe70..0687ab91 100644 --- a/src/ApiEncoder.js +++ b/src/ApiEncoder.js @@ -12,6 +12,7 @@ const TYPES = { contract_bytearray: {tag: 'cb', size: 0, encoder: base64check}, contract_pubkey: {tag: 'ct', size: 32, encoder: base58check}, account_pubkey: {tag: 'ak', size: 32, encoder: base58check}, + account_seckey: {tag: 'sk', size: 32, encoder: base58check}, channel: {tag: 'ch', size: 32, encoder: base58check}, oracle_pubkey: {tag: 'ok', size: 32, encoder: base58check}, oracle_query_id: {tag: 'oq', size: 32, encoder: base58check}, @@ -32,6 +33,7 @@ const TAG2TYPE = { cb: 'contract_bytearray', ct: 'contract_pubkey', ak: 'account_pubkey', + sk: 'account_seckey', ch: 'channel', ok: 'oracle_pubkey', oq: 'oracle_query_id', diff --git a/tests/ApiEncoder.js b/tests/ApiEncoder.js index 581b59ac..7a243591 100644 --- a/tests/ApiEncoder.js +++ b/tests/ApiEncoder.js @@ -7,7 +7,7 @@ const payload = mkPayload(32) const payload64 = mkPayload(64) test('Encode', t => { - t.plan(17) + t.plan(18) t.deepEqual( encoder.encode('contract_bytearray', new Uint8Array()), @@ -39,6 +39,11 @@ test('Encode', t => { 'ak_16qJFWMMHFy3xDdLmvUeyc2S6FrWRhJP51HsvDYdz9d1FsYG' ) + t.deepEqual( + encoder.encode('account_seckey', payload), + 'sk_16qJFWMMHFy3xDdLmvUeyc2S6FrWRhJP51HsvDYdz9d1FsYG' + ) + t.deepEqual( encoder.encode('channel', payload), 'ch_16qJFWMMHFy3xDdLmvUeyc2S6FrWRhJP51HsvDYdz9d1FsYG' @@ -110,7 +115,7 @@ test('Encode errors', t => { }) test('Decode', t => { - t.plan(17) + t.plan(18) t.deepEqual( encoder.decode('cb_Xfbg4g=='), new Uint8Array() @@ -141,6 +146,11 @@ test('Decode', t => { payload ) + t.deepEqual( + encoder.decode('sk_16qJFWMMHFy3xDdLmvUeyc2S6FrWRhJP51HsvDYdz9d1FsYG'), + payload + ) + t.deepEqual( encoder.decode('ch_16qJFWMMHFy3xDdLmvUeyc2S6FrWRhJP51HsvDYdz9d1FsYG'), payload