Skip to content

Commit

Permalink
Feature: Added bidds decentralized domains support (#19)
Browse files Browse the repository at this point in the history
* Added bidds decentralized domains support

* chore: updated docs and test for bidds domains

* chore: bumped version to 1.11.0 and docs update

* fix: updated top level domains for bidds

---------

Co-authored-by: Henk ter Harmsel <henk@chaink.it>
Co-authored-by: dineshnadimpalli <dineshn.consult@gmail.com>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent a0c5780 commit ff00929
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ We support the following name services -
5. [SpaceId](https://space.id)
6. [SNS](https://www.sns.id)
7. [DegeNS](https://www.degens.domains)
8. [Bidds Decentralized Domains](https://bidds.com)

We also allow you to add your own name service for custom use-cases. You can look at the docs for the same [here](https://leapwallet.github.io/name-matcha/docs/advanced#custom-name-services).
1 change: 1 addition & 0 deletions docs/components/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const nsMap = {
[services.sns]: 'SNS',
[services.nibId]: 'Nib ID',
[services.degeNS]: 'DegeNS',
[services.bdd]: 'BDD',
}

const nsList = Object.entries(nsMap)
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/advanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To list all registered name services, you can call the `listServices` method. He
import nameMatcha from '@leapwallet/name-matcha'

const services = nameMatcha.listServices()
// ['icns', 'ibcDomains', 'stargazeNames', 'archIds', 'spaceIds', 'sns', 'nibId', 'degeNS']
// ['icns', 'ibcDomains', 'stargazeNames', 'archIds', 'spaceIds', 'sns', 'nibId', 'degeNS', 'bidds']
```

## Custom Name Services
Expand Down
1 change: 1 addition & 0 deletions docs/pages/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ For this purpose, the community has come up with quite a few name-services, a fe
5. [SpaceId](https://space.id)
6. [SNS](https://www.sns.id)
7. [DegeNS](https://www.degens.domains)
8. [Bidds Decentralized Domains](https://bidds.com)

These services allow users to register a name for their wallet address. However, there is no standard way to resolve these names to wallet addresses. This is where _Name Matcha_ comes in. It is a javascript library that allows you to resolve names to wallet addresses in a standard way.

Expand Down
7 changes: 5 additions & 2 deletions docs/pages/docs/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ The output will be an object with the service as key and the address as value:
spaceIds: null,
sns: null,
nibId: null,
degeNS: null
degeNS: null,
bidds: null
}
```

Expand Down Expand Up @@ -110,7 +111,8 @@ The output will be an object with the service as key and the name as value:
spaceIds: null,
sns: null,
nibId: null,
degeNS: 'ligma.pp'
degeNS: 'ligma.pp',
bidds: null
}
```

Expand Down Expand Up @@ -156,3 +158,4 @@ try {
- [SNS](https://www.sns.id) - Injective .sol domains
- [NIB ID](https://nibid.app) - .nibi domains on Nibiru
- [DegeNS](https://www.degens.domains) - Degen Name Service on Sei Network
- [Bidds Decentralized Domains](https://bidds.com) - Coreum .core domains
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@leapwallet/name-matcha",
"description": "Name Matcha is a javascript library for resolving names to wallet addresses in the cosmos universe.",
"version": "1.10.0",
"version": "1.11.0",
"repository": "https://github.com/leapwallet/name-matcha",
"author": "Leap Wallet",
"license": "MIT",
Expand Down
73 changes: 73 additions & 0 deletions src/registry/bdd.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { describe, expect, it } from 'vitest'
import { BDD } from './bdd'

describe('BDD', () => {
const resolver = new BDD()

it('should be defined', () => {
expect(resolver).toBeDefined()
})

it.concurrent(
'should resolve thisisatest.core',
async () => {
const result = await resolver.resolve('thisisatest.core', 'testnet')
expect(result).toBe('testcore1y7d6cacnu43fhjlclr67tz6n4wqqe8h8mwdgk9')
},
10000
)

it.concurrent(
'should resolve bdd-registrar-test.core',
async () => {
const result = await resolver.resolve(
'bdd-registrar-test.core',
'testnet'
)
expect(result).toBe('testcore10g5cy007hcmzhh4ta9sne0trasfds59lfdtd2g')
},
10000
)

it.concurrent(
'should return bdd-registrar-test.core',
async () => {
const result = await resolver.lookup(
'testcore10g5cy007hcmzhh4ta9sne0trasfds59lfdtd2g',
'testnet'
)
expect(result).toBe('bdd-registrar-test.core')
},
10000
)

it.concurrent(
'should resolve 5534534g.core',
async () => {
const result = await resolver.resolve('5534534g.core', 'mainnet')
expect(result).toBe('core108a6808s9srwz548x58z7cjt08eur54gjtsv92')
},
10000
)

it.concurrent(
'should resolve bdd-registrar.core',
async () => {
const result = await resolver.resolve('bdd-registrar.core', 'mainnet')
expect(result).toBe('core10g5cy007hcmzhh4ta9sne0trasfds59lless97')
},
10000
)

it.concurrent(
'should return bdd-registrar.core',
async () => {
const result = await resolver.lookup(
'core10g5cy007hcmzhh4ta9sne0trasfds59lless97',
'mainnet'
)
expect(result).toBe('bdd-registrar.core')
},
10000
)
})
88 changes: 88 additions & 0 deletions src/registry/bdd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {
Addr,
MatchaError,
MatchaErrorType,
NameService,
Network,
RpcURLs
} from './name-service'
import { decode, encode } from 'bech32'

export const serviceID = 'bdd'

const rpcUrls = {
mainnet: 'https://full-node.mainnet-1.coreum.dev:26657',
testnet: 'https://full-node.testnet-1.coreum.dev:26657'
}

export class BDD extends NameService {
serviceID = serviceID
chain = 'coreum'
contractAddress = {
mainnet: 'core1z22n0xy004sxm5w9fms48exwpl3vwqxd890nt8ve0kwjj048tgqstlqf6f',
testnet: 'testcore1uwe9yemth6gr58tm56sx3u37t0c5rhmk963fjt480y4nz3cfxers9fn2kh'
}

async resolve(name: string, network: Network): Promise<string> {
const client = await this.getCosmWasmClient(rpcUrls[network])
try {
const result = await client.queryContractSmart(
this.contractAddress[network],
{
resolve: {
name
}
}
)
if (!result) {
throw new MatchaError('', MatchaErrorType.NOT_FOUND)
}
return result
} catch (err) {
throw new MatchaError('', MatchaErrorType.NOT_FOUND)
}
}

async lookup(
address: string,
network: Network,
options?: {
rpcUrls?: RpcURLs
}
): Promise<string> {
const client = await this.getCosmWasmClient(
options?.rpcUrls?.[serviceID]?.[network] ?? rpcUrls[network]
)

const addr: Addr = {
prefix: null,
words: null
}
try {
const { prefix, words } = decode(address)
addr.prefix = prefix
addr.words = words
} catch (e) {
throw new MatchaError('', MatchaErrorType.INVALID_ADDRESS)
}

const prefix = network === 'mainnet' ? 'core' : 'testcore'
const coreAddress = encode(prefix, addr.words)
try {
const res = await client?.queryContractSmart(
this.contractAddress[network],
{
primary: {
address: coreAddress
}
}
)
if (!res) {
throw new MatchaError('', MatchaErrorType.NOT_FOUND)
}
return res
} catch (e) {
throw new MatchaError('', MatchaErrorType.NOT_FOUND)
}
}
}
4 changes: 3 additions & 1 deletion src/registry/name-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type AllowedTopLevelDomains = {
stargazeNames?: string[]
spaceIds?: string[]
sns?: string[]
bdd?: string[]
nibId?: string[]
degeNS?: string[]
}
Expand All @@ -49,7 +50,8 @@ export type RpcURLs = {
archIds?: rpcUrls
stargazeNames?: rpcUrls
spaceIds?: rpcUrls
sns?: rpcUrls
sns?: rpcUrls,
bdd?: rpcUrls
nibId?: rpcUrls
degeNS?: rpcUrls
}
Expand Down
73 changes: 68 additions & 5 deletions src/registry/registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('registry', () => {
[services.stargazeNames]: true,
[services.spaceIds]: true,
[services.sns]: true,
[services.bdd]: true,
[services.nibId]: true,
[services.degeNS]: true
})
Expand Down Expand Up @@ -113,6 +114,7 @@ describe('registry', () => {
stargazeNames: null,
sns: null,
spaceIds: null,
bdd: null,
nibId: null,
degeNS: null
})
Expand All @@ -131,6 +133,7 @@ describe('registry', () => {
sns: null,
stargazeNames: 'cosmos19vf5mfr40awvkefw69nl6p3mmlsnacmm28xyqh',
spaceIds: null,
bdd: null,
nibId: null,
degeNS: null
})
Expand All @@ -149,6 +152,7 @@ describe('registry', () => {
stargazeNames: null,
sns: null,
spaceIds: 'sei1tmew60aj394kdfff0t54lfaelu3p8j8lz93pmf',
bdd: null,
nibId: null,
degeNS: 'sei1tmew60aj394kdfff0t54lfaelu3p8j8lz93pmf'
})
Expand All @@ -168,7 +172,8 @@ describe('registry', () => {
sns: null,
spaceIds: null,
nibId: null,
degeNS: 'sei1yq82exxgmgvrdvq9a0pvzrvra5g3mvclhmagxv'
degeNS: 'sei1yq82exxgmgvrdvq9a0pvzrvra5g3mvclhmagxv',
bdd: null
})
},
10000
Expand Down Expand Up @@ -227,7 +232,8 @@ describe('registry', () => {
sns: null,
spaceIds: null,
nibId: null,
degeNS: null
degeNS: null,
bdd: null,
})
}
)
Expand All @@ -246,7 +252,8 @@ describe('registry', () => {
sns: null,
spaceIds: null,
nibId: null,
degeNS: null
degeNS: null,
bdd: null,
})
}
)
Expand All @@ -265,7 +272,8 @@ describe('registry', () => {
sns: null,
spaceIds: 'allen.sei',
nibId: null,
degeNS: 'allen.sei'
degeNS: 'allen.sei',
bdd: null,
})
}
)
Expand Down Expand Up @@ -300,7 +308,62 @@ describe('registry', () => {
})

it.concurrent(
'should resolve zucky.nibi',
'should resolve bdd-registrar.core',
async () => {
const result = await registry.resolve('bdd-registrar.core', services.bdd)
expect(result).toBe('core10g5cy007hcmzhh4ta9sne0trasfds59lless97')
},
10000
)

it.concurrent('should return bdd-registrar.core', async () => {
const result = await registry.lookup(
'core10g5cy007hcmzhh4ta9sne0trasfds59lless97',
services.bdd
)
expect(result).toBe('bdd-registrar.core')
})

it.concurrent(
'should resolveAll for bdd-registrar.core',
async () => {
const res = await registry.resolveAll('bdd-registrar.core')
expect(res).toEqual({
archIds: null,
icns: null,
ibcDomains: null,
stargazeNames: null,
sns: null,
spaceIds: null,
nibId: null,
degeNS: null,
bdd: 'core10g5cy007hcmzhh4ta9sne0trasfds59lless97',
})
},
10000
)

it.concurrent(
'should lookupAll for core10g5cy007hcmzhh4ta9sne0trasfds59lless97',
async () => {
const res = await registry.lookupAll(
'core10g5cy007hcmzhh4ta9sne0trasfds59lless97'
)
expect(res).toEqual({
archIds: null,
icns: null,
ibcDomains: null,
stargazeNames: null,
sns: null,
spaceIds: null,
nibId: null,
degeNS: null,
bdd: 'bdd-registrar.core',
})
}
)

it.concurrent('should resolve zucky.nibi',
async () => {
const result = await registry.resolve('zucky.nibi', services.nibId)
expect(result).toBe('nibi1kmx4u9q4dcf36qpp0wgymfc3yzj3r4epnu4m6m')
Expand Down
Loading

0 comments on commit ff00929

Please sign in to comment.