Skip to content

Commit d7cb128

Browse files
authored
Merge pull request #57 from dotbitHQ/feat/validDotbitAliasAddresses
feat: add validDotbitAliasAddresses.
2 parents 3b67e04 + b885cb1 commit d7cb128

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

docs/api/dotbit.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- [profiles(account, key)](#profilesaccount-key)
2727
- [avatar(account)](#avataraccount)
2828
- [verifyAddrsByAccount(address, account, subAccount, verifyType)](#verifyaddrsbyaccountaddress-account-subaccount-verifytype)
29+
- [validDotbitAliasAddresses(account)](#validdotbitaliasaddresses-account)
2930

3031
## constructor(config)
3132
To create a new DotBit instance.
@@ -754,3 +755,25 @@ dotbit.verifyAddrsByAccount(
754755
// The printed result would be like:
755756
true
756757
```
758+
759+
## validDotbitAliasAddresses (account)
760+
Query the valid alias address using the .bit alias.
761+
### Parameters
762+
- account: `string`. a .bit alias.
763+
### Return Value
764+
Promise\<`BitKeyInfo[]`>
765+
### Example
766+
```javascript
767+
dotbit.validDotbitAliasAddresses('imac.bit').then(console.log)
768+
769+
// The printed result would be like:
770+
[
771+
{
772+
"type":"blockchain",
773+
"key_info":{
774+
"coin_type":"60",
775+
"key":"0x15a33588908cf8edb27d1abe3852bf287abd3891"
776+
}
777+
}
778+
]
779+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dotbit",
3-
"version": "0.4.22",
3+
"version": "0.4.23",
44
"description": "A complete .bit SDK and utilities in TypeScript",
55
"author": "Jeff Jing <https://github.com/zgayjjf>",
66
"license": "MIT",

src/DotBit.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,15 @@ export class DotBit {
196196
* @param subAccount
197197
* @param verifyType default 0 === "owner", 1 === "manager"
198198
*/
199-
async verifyAddrsByAccount (address: string, mainAccount: string, subAccount?: string, verifyType?: number){
199+
async verifyAddrsByAccount (address: string, mainAccount: string, subAccount?: string, verifyType?: number) {
200200
return await this.bitIndexer.subAccountVerify(address, mainAccount, subAccount, verifyType)
201201
}
202+
203+
/**
204+
* Query the valid alias address using the .bit alias.
205+
* @param account
206+
*/
207+
async validDotbitAliasAddresses (account: string) {
208+
return await this.bitIndexer.validDotbitAliasAddresses(account)
209+
}
202210
}

src/fetchers/BitIndexer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
BitAccountInfo,
44
BitAccountList,
55
BitAccountRecord,
6+
BitKeyInfo,
67
DasAccountRecords,
78
DasServerInfo,
89
KeyInfo,
@@ -89,4 +90,13 @@ export class BitIndexer {
8990
}])
9091
.then(result => result.is_subdid)
9192
}
93+
94+
/**
95+
* Query the valid alias address using the .bit alias.
96+
* @param account
97+
*/
98+
validDotbitAliasAddresses (account: string): Promise<BitKeyInfo[]> {
99+
return this.request('das_accountReverseAddress', [{ account }])
100+
.then(result => result.list)
101+
}
92102
}

tests/DotBit.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,15 @@ describe('verifyAddrsByAccount', function () {
210210
)
211211
expect(isValid).toBe(true)
212212
})
213+
213214
it('should work', async function () {
214215
const isValid = await dotbitTest.verifyAddrsByAccount(
215216
'0xC72B6f66017246d6A7f159F5C2BF358188AD9ECa',
216217
'leonx.bit',
217218
)
218219
expect(isValid).toBe(true)
219220
})
221+
220222
it('should work', async function () {
221223
const isValid = await dotbitTest.verifyAddrsByAccount(
222224
'0xC72B6f66017246d6A7f159F5C2BF358188AD9ECa',
@@ -225,6 +227,7 @@ describe('verifyAddrsByAccount', function () {
225227
)
226228
expect(isValid).toBe(false)
227229
})
230+
228231
it('should work', async function () {
229232
const isValid = await dotbitTest.verifyAddrsByAccount(
230233
'0xC72B6f66017246d6A7f159F5C2BF358188AD9ECa',
@@ -233,13 +236,15 @@ describe('verifyAddrsByAccount', function () {
233236
)
234237
expect(isValid).toBe(false)
235238
})
239+
236240
it('should work', async function () {
237241
const isValid = await dotbitTest.verifyAddrsByAccount(
238242
'0xC72B6f66017246d6A7f159F5C2BF358188AD9ECa',
239243
'123.bit',
240244
)
241245
expect(isValid).toBe(false)
242246
})
247+
243248
it('should work', async function () {
244249
const isValid = await dotbitTest.verifyAddrsByAccount(
245250
'0xC72B6f66017246d6A7f159F5C2BF358188AD9ECa',
@@ -250,3 +255,11 @@ describe('verifyAddrsByAccount', function () {
250255
expect(isValid).toBe(true)
251256
})
252257
})
258+
259+
describe('validDotbitAliasAddresses', function () {
260+
it('should work', async function () {
261+
const addresses = await dotbitProd.validDotbitAliasAddresses('imac.bit')
262+
expect(addresses).toBeInstanceOf(Array)
263+
expect(addresses.length).toBe(0)
264+
})
265+
})

0 commit comments

Comments
 (0)