Skip to content

Commit

Permalink
Add support for account_seckey in API encoder (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
dincho authored Nov 4, 2024
1 parent 0c2300d commit 4eb490f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/ApiEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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',
Expand Down
14 changes: 12 additions & 2 deletions tests/ApiEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -141,6 +146,11 @@ test('Decode', t => {
payload
)

t.deepEqual(
encoder.decode('sk_16qJFWMMHFy3xDdLmvUeyc2S6FrWRhJP51HsvDYdz9d1FsYG'),
payload
)

t.deepEqual(
encoder.decode('ch_16qJFWMMHFy3xDdLmvUeyc2S6FrWRhJP51HsvDYdz9d1FsYG'),
payload
Expand Down

0 comments on commit 4eb490f

Please sign in to comment.