Skip to content

Commit

Permalink
fix(utils): rename the arg field in params of utils#fullPayloadToAddr…
Browse files Browse the repository at this point in the history
…ess to args

BREAKING CHANGE: The arg field in params of utils#fullPayloadToAddress is renamed to args
  • Loading branch information
Keith-CY committed Jul 9, 2020
1 parent 9517cae commit 08dcc0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions packages/ckb-sdk-utils/__tests__/utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('blake', () => {
})

describe('bech32', () => {
bech32Fixtures.bech32.valid.forEach((f) => {
bech32Fixtures.bech32.valid.forEach(f => {
it(`fromWords/toWords ${f.hex}`, () => {
if (f.hex) {
const words = bech32.toWords(Buffer.from(f.hex, 'hex'))
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('scriptToHash', () => {
scriptHash: '0xd39f84d4702f53cf8625da4411be1640b961715cb36816501798fedb70b6e0fb',
},
}
test.each(Object.keys(fixtures))('%s', (fixtureName) => {
test.each(Object.keys(fixtures))('%s', fixtureName => {
const fixture = fixtures[fixtureName]
const scriptHash = scriptToHash(fixture.script)
expect(scriptHash).toBe(fixture.scriptHash)
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('address', () => {
it('fullPayloadToAddress with hash type of Data', () => {
const fixture = {
params: {
arg: '0x36c329ed630d6ce750712a477543672adab57f4c',
args: '0x36c329ed630d6ce750712a477543672adab57f4c',
type: AddressType.DataCodeHash,
prefix: 'ckt',
codeHash: '0xa656f172b6b45c245307aeb5a7a37a176f002f6f22e92582c58bf7ba362e4176',
Expand All @@ -233,7 +233,7 @@ describe('address', () => {
it('fullPayloadToAddress with hash type of Type', () => {
const fixture = {
params: {
arg: '0x36c329ed630d6ce750712a477543672adab57f4c',
args: '0x36c329ed630d6ce750712a477543672adab57f4c',
type: AddressType.TypeCodeHash,
prefix: 'ckt',
codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2',
Expand All @@ -247,7 +247,7 @@ describe('address', () => {
it('fullPayloadToAddress with default params of type = AddressType.DataCodeHash and prefix = ckt', () => {
const fixture = {
params: {
arg: '0x36c329ed630d6ce750712a477543672adab57f4c',
args: '0x36c329ed630d6ce750712a477543672adab57f4c',
codeHash: '0xa656f172b6b45c245307aeb5a7a37a176f002f6f22e92582c58bf7ba362e4176',
},
expected: 'ckt1q2n9dutjk669cfznq7httfar0gtk7qp0du3wjfvzck9l0w3k9eqhvdkr98kkxrtvuag8z2j8w4pkw2k6k4l5czshhac',
Expand Down Expand Up @@ -322,7 +322,7 @@ describe('address', () => {
address: 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83',
},
}
test.each(Object.keys(pubkeyToAddressFixtures))('%s', (caseName) => {
test.each(Object.keys(pubkeyToAddressFixtures))('%s', caseName => {
const fixture = pubkeyToAddressFixtures[caseName]
const address = pubkeyToAddress(hexToBytes(fixture.pubkey), fixture.config)
expect(address).toBe(fixture.address)
Expand Down
20 changes: 10 additions & 10 deletions packages/ckb-sdk-utils/src/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const defaultAddressOptions = {
export const toAddressPayload = (
args: string | Uint8Array,
type: AddressType = AddressType.HashIdx,
codeHashOrCodeHashIndex: CodeHashIndex | CKBComponents.Hash256 = '0x00'
codeHashOrCodeHashIndex: CodeHashIndex | CKBComponents.Hash256 = '0x00',
): Uint8Array => {
if (typeof args === 'string') {
if (!args.startsWith('0x')) {
Expand All @@ -53,41 +53,41 @@ export const toAddressPayload = (
/**
* @name bech32Address
* @description generate the address by bech32 algorithm
* @param arg, used as the identifier of an address, usually the public key hash is used.
* @param args, used as the identifier of an address, usually the public key hash is used.
* @param {string} prefix, the prefix precedes the address.
* @param {string} type, used to indicate which format is adopted to compose the address.
* @param {string} codeHashOrCodeHashIndex, the referenced code hash or code hash index the address binds to.
*/
export const bech32Address = (
arg: Uint8Array | string,
args: Uint8Array | string,
{
prefix = AddressPrefix.Testnet,
type = AddressType.HashIdx,
codeHashOrCodeHashIndex = '0x00',
}: AddressOptions = defaultAddressOptions
) => bech32.encode(prefix, bech32.toWords(toAddressPayload(arg, type, codeHashOrCodeHashIndex)))
}: AddressOptions = defaultAddressOptions,
) => bech32.encode(prefix, bech32.toWords(toAddressPayload(args, type, codeHashOrCodeHashIndex)))

/**
* @name fullPayloadToAddress
* @description generate the address with payload in full version format.
* @param {string} arg, used as the identifier of an address.
* @param {string} args, used as the identifier of an address.
* @param {string} prefix, the prefix precedes the address.
* @param {string} type, used to indicate which format the address conforms to,
* with hash type of Data or with hash type of Type.
* @param {string} codeHash, the code hash used in the full version payload.
*/
export const fullPayloadToAddress = ({
arg,
args,
prefix = AddressPrefix.Testnet,
type = AddressType.DataCodeHash,
codeHash,
}: {
arg: string
args: string
prefix: AddressPrefix
type: AddressType.DataCodeHash | AddressType.TypeCodeHash
codeHash: CKBComponents.Hash256
}) =>
bech32Address(arg, {
bech32Address(args, {
prefix,
type,
codeHashOrCodeHashIndex: codeHash,
Expand All @@ -99,7 +99,7 @@ export const pubkeyToAddress = (
prefix = AddressPrefix.Testnet,
type = AddressType.HashIdx,
codeHashOrCodeHashIndex = '0x00' as CodeHashIndex,
}: AddressOptions = defaultAddressOptions
}: AddressOptions = defaultAddressOptions,
) => {
const publicKeyHash = blake160(pubkey)
return bech32Address(publicKeyHash, {
Expand Down

0 comments on commit 08dcc0d

Please sign in to comment.