Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

feat: add name service #1

Merged
merged 7 commits into from
Oct 4, 2022
Merged

feat: add name service #1

merged 7 commits into from
Oct 4, 2022

Conversation

arein
Copy link
Member

@arein arein commented Sep 28, 2022

Adding Solana Name Service (SNS) support.

Code is copied from @bonfida/spl with two adjustments:

  • removed twitter logic
  • only querying max 5 domains

Notes

For @devceline - I'm a bit confused why we have our own cluster concept which seems like a reimplementation of a lot of things that are already implemented in Connection. I am not using it here - I am using a Connection object.

Following your recommendation and our tenet to keep the footprint low I copied a lot of the logic from SPL over here in accordance with their license.

Testing

Tested locally using various Bonfida domains.

Comment on lines 71 to 201
export async function getHashedName(name: string): Promise<Buffer> {
const input = HASH_PREFIX + name;
return Buffer.from(Hex.stringify(sha256(input)), 'hex');
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/solana-labs/solana-program-library/blob/b5e301b2100070f6713da9bedfccdbb313f595fb/name-service/js/src/utils.ts#L95-L99

i wasn't able to get the createHash method using crypto to work. Got a Module "crypto" has been externalized for browser compatibility. Cannot access "crypto.createHash" in client code

@arein arein marked this pull request as ready for review October 2, 2022 14:39
Copy link
Collaborator

@devceline devceline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using our own fetch method to target clusters gives us more fine-grain control over error handling, message emitting, etc and makes it more future proof.

For a library that's on lower level than typical endd-user lib. I know this is controversial, but I believe the pros outweigh the cons.

It's awesome you got this working, I'm going to approve for now, but I might go in and update the implementation to use the cluster fetch method

package.json Outdated
Comment on lines 23 to 24
"@types/bn.js": "^5.1.1",
"@types/crypto-js": "^4.1.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these need to be devDependencies

return otherDomains.length > 0 ? otherDomains[0] : null;
}

async function getSolDomainsFromPublicKey(connection: Connection, wallet: PublicKey):Promise<string[]>{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't to trouble users with instantiating a PublicKey. Function APIs should be similar to Wagmi, wehre you just pass base-58 encoded pubkey.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is not exposed to users.

Comment on lines +106 to +112
static async retrieve(connection: Connection, key: PublicKey) {
const accountInfo = await connection.getAccountInfo(key);
if (!accountInfo || !accountInfo.data) {
throw new Error("Favourite domain not found");
}
return this.deserialize(accountInfo.data);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most these methods can be replaced with just calls to the base connector's requestCluster

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's quite a bit of serde logic going on in Connection. The base connector doesn't do that and it's quite a bit of copy/pasta to get that working. Happy for you to prove me wrong. But we already have the Connection in the footprint so might as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually spent quite a bit of time trying to get this to work. I highly suggest you timebox that effort if you go down that rabbithole :)

@arein arein merged commit 9e1421e into development Oct 4, 2022
@arein arein deleted the feat/name-service branch October 4, 2022 02:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants