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

feat: implement record interface #16

Merged
merged 1 commit into from
Dec 14, 2022
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: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
},
"dependencies": {
"@ensdomains/ensjs": "^2.1.0",
"dotbit": "^0.4.13"
"@ethersproject/providers": "^5.7.2",
"dotbit": "^0.4.13",
"ethers": "^5.7.2"
}
}
5 changes: 3 additions & 2 deletions src/createInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ethers } from 'ethers'
import { AllDID } from './AllDID'
import { DotbitService, DotbitServiceOptions } from './services/DotbitService'
import { EnsService, EnsServiceOptions } from './services/EnsService'
import { SIDService } from './services/SIDService'

export interface CreateInstanceOptions {
'dotbit': DotbitServiceOptions,
Expand All @@ -22,11 +23,11 @@ export const defaultCreateInstanceOptions: CreateInstanceOptions = {
}
}

export function createInstance (options: CreateInstanceOptions) {
export function createInstance (options = defaultCreateInstanceOptions) {
const alldid = new AllDID()
const dotbitService = new DotbitService(options.dotbit)
const ensService = new EnsService(options.ens)
const sidService = new DotbitService(options.sid)
const sidService = new SIDService(options.sid)

alldid.installService(dotbitService)
alldid.installService(ensService)
Expand Down
10 changes: 5 additions & 5 deletions src/services/DotbitService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createInstance, DotBit, isSupportedAccount } from 'dotbit'
import { NamingService } from './NamingService'
import { NamingService, RecordItem, RecordItemAddr } from './NamingService'

export type DotbitServiceOptions = any // todo: export config interface from dotbit.js

Expand Down Expand Up @@ -36,19 +36,19 @@ export class DotbitService extends NamingService {
return null
}

record (name: string, key: string): Promise<string> {
record (name: string, key: string): Promise<RecordItem> {
return null
}

records (name: string, keys?: string[]): Promise<Record<string, string>> {
records (name: string, keys?: string[]): Promise<RecordItem[]> {
return null
}

addrs (name: string, keys?: string | string[]): Promise<string> {
addrs (name: string, keys?: string | string[]): Promise<RecordItemAddr[]> {
return null
}

addr (name: string): Promise<string> {
addr (name: string): Promise<RecordItemAddr> {
return null
}

Expand Down
10 changes: 5 additions & 5 deletions src/services/EnsService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ENS from '@ensdomains/ensjs'
import { Provider, ExternalProvider } from '@ethersproject/providers'
import { NamingService } from './NamingService'
import { NamingService, RecordItem, RecordItemAddr } from './NamingService'

export interface EnsServiceOptions {
provider: Provider | ExternalProvider,
Expand Down Expand Up @@ -56,19 +56,19 @@ export class EnsService extends NamingService {
return null
}

record (name: string, key: string): Promise<string> {
record (name: string, key: string): Promise<RecordItem> {
return null
}

records (name: string, keys?: string[]): Promise<Record<string, string>> {
records (name: string, keys?: string[]): Promise<RecordItem[]> {
return null
}

addrs (name: string, keys?: string | string[]): Promise<string> {
addrs (name: string, keys?: string | string[]): Promise<RecordItemAddr[]> {
return null
}

addr (name: string): Promise<string> {
addr (name: string): Promise<RecordItemAddr> {
return null
}

Expand Down
30 changes: 24 additions & 6 deletions src/services/NamingService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import { AllDIDError, AllDIDErrorCode } from '../errors/AllDIDError'

export interface RecordItem {
key: string, // full key, like `address.60`
type: string, // the type of the key, like `address`
subtype: string, // the subtype of the key, like `60`
label: string, // the user customized label of the key, like `personal`
value: string, // the value of the key, like `0x123...abc`
ttl: number, // the ttl of the key
}

export interface RecordItemAddr extends RecordItem {
symbol: string, // the symbol of the coin_type, like 'ETH'
}

export interface RecordItemDweb extends RecordItem {
protocolType: string,
decoded: string,
}

export abstract class NamingService {
abstract serviceName: string

Expand Down Expand Up @@ -32,14 +50,14 @@ export abstract class NamingService {

abstract tokenId (name: string): Promise<string>

abstract records (name: string, keys?: string | string[]): Promise<Record<string, string>>
abstract record (name: string, key: string): Promise<string>
abstract records (name: string, keys?: string | string[]): Promise<RecordItem[]>
abstract record (name: string, key: string): Promise<RecordItem>

abstract addrs (name: string, keys?: string | string[]): Promise<string>
abstract addr (name: string, keys?: string | string[]): Promise<string>
abstract addrs (name: string, keys?: string | string[]): Promise<RecordItemAddr[]>
abstract addr (name: string, keys?: string | string[]): Promise<RecordItemAddr>

abstract dwebs (name: string, keys?: string | string[]): Promise<string>
abstract dweb (name: string): Promise<string>
// abstract dwebs (name: string, keys?: string | string[]): Promise<RecordItemDweb[]>
// abstract dweb (name: string): Promise<RecordItemDweb>

abstract reverse (address: string, currencyTicker: string): Promise<string | null>

Expand Down
17 changes: 17 additions & 0 deletions tests/createInstance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createInstance } from '../src/createInstance'

describe('AllDID', () => {
const alldid = createInstance()

describe('isSupported', () => {
it('support .bit .eth .bnb', () => {
expect(alldid.isSupported('abc.bit')).toBe(true)
expect(alldid.isSupported('abc.eth')).toBe(true)
expect(alldid.isSupported('abc.bnb')).toBe(true)
})

it('do not support abc.bat', () => {
expect(alldid.isSupported('abc.bat')).toBe(false)
})
})
})