Code Monkey home page Code Monkey logo

sns-sdk's Introduction

SNS SDK



SNS SDK monorepo


๐Ÿšง This repository is in active development and is subject to changes ๐Ÿšง



Table of contents


  1. SNS documentation
  2. Javascript
  3. Rust
  4. SDK Proxy
  5. Python
  6. Java
  7. Swift
  8. CLI
  9. React
  10. Vue
  11. Examples
  • Resolving a domain
  1. Bounties

SNS documentation


This repository contains the Developer documentation specifically for the SNS SDK. You can find the general SNS documentation at sns.guide


Javascript


yarn add @bonfida/spl-name-service
npm i @bonfida/spl-name-service

The JS SDK is the most complete SDK, it contains all the utils methods to interact with domain names as well as instruction builders to register domain names.


Rust


The Rust SDK provides everything you need for resolving domain ownership and records within the Solana Name Service (SNS)

  • resolve_owner: Resolves the owner of a given domain
  • resolve_record: Resolves a specific record of a given domain
  • resolve_name_registry: Resolves the name registry of a given public key
  • resolve_name_registry_batch: Resolves the name registry of a given list of public keys
  • resolve_reverse: Resolves the reverse record of a given public key
  • resolve_reverse_batch: Resolves the reverse records for a given list of public keys
  • get_domains_owner: Retrieves all domains owned by a given public key
  • get_subdomains: Retrieves all subdomains of a given parent domain
  • resolve_nft_owner: Resolves the NFT owner of a given domain key
  • get_domain_key: Takes a domain string and a boolean indicating whether it is a record. It returns the public key for the given domain, or an error if the domain is invalid
  • get_reverse_key: Takes a domain string and returns the public key for the reverse lookup account of the domain, or an error if the domain is invalid
  • get_domain_mint: Takes a domain key and returns the corresponding domain NFT mint's public key

The functions in this code are available in both blocking and non-blocking (asynchronous) versions. To use the blocking version one must enable the blocking feature.


SDK Proxy


The SDK proxy is a Cloudflare worker that proxies the JS SDK via REST calls. It's meant to be used if you are programming in a language that is not supported. It currently supports the following endpoints:

  • GET /resolve/:domain: Resolves the current owner of domain
  • GET /domain-key/:domain: Returns the public key of the domain account
  • GET /domains/:owner: Returns the list of domains (public keys) owned by owner
  • GET /reverse-key/:domain Returns the key of the reverse account of domain
  • GET /record-key/:domain/:record: Returns the public key of the record of domain
  • GET /record/:domain/:record: Returns the content of the record of domain. The result is a base64 encoded buffer.
  • GET /favorite-domain/:owner: Returns the favorite domain of owner. If owner has not set up a favorite domain it returns null
  • GET /types/record: Returns the list of supported records
  • GET /reverse-lookup/:pubkey: Returns the reverse lookup of pubkey
  • GET /subdomains/:parent: Returns all the subdomains of parent
  • GET /register?buyer={buyer}&domain={domain}&space={space}&serialize={serialize}: This endpoint can be used to register domain for buyer. Additionaly, the buyer dans specify the space it wants to allocate for the domain account. In the case where serialize is true the endpoint will return the transaction serialized in the wire format base64 encoded. Otherwise it will return the instruction in the following format: { programId: string, keys: {isWritable: boolean, isSigner: boolean, pubkey: string}[], data: string } where data is base64 encoded. This endpoint also supports the optional mint parameter to change the mint of the token used for registration (currently supports USDC, USDT, FIDA and wSOL), if mint is omitted it defaults to USDC.

The SDK proxy is deployed at: https://sns-sdk-proxy.bonfida.workers.dev/


CLI


The CLI can be installed with:

cargo install --git https://github.com/Bonfida/sns-sdk.git sns

The CLI has the following commands:

  • sns resolve <domains>
  • sns domains <owners>
  • sns burn <domains> <keypair_path>
  • sns transfer <keypair_path> <new_owner_key> <domains>
  • sns lookup <domains>
  • sns reverse-lookup <key>
  • sns bridge <target_chain> <domain> <keypair_path>
  • sns register <keypair_path> <space> <domains>

For instance

$ sns resolve bonfida solana.sol coinbase

+------------+----------------------------------------------+----------------------------------------------------------------------------------+
| Domain     | Owner                                        | Explorer                                                                         |
+------------+----------------------------------------------+----------------------------------------------------------------------------------+
| bonfida    | HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA | https://explorer.solana.com/address/HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA |
+------------+----------------------------------------------+----------------------------------------------------------------------------------+
| solana.sol | 3Wnd5Df69KitZfUoPYZU438eFRNwGHkhLnSAWL65PxJX | https://explorer.solana.com/address/3Wnd5Df69KitZfUoPYZU438eFRNwGHkhLnSAWL65PxJX |
+------------+----------------------------------------------+----------------------------------------------------------------------------------+
| coinbase   | 7sF2JumHpWiPjS3XtnQ8cKraTzzfcGSvQHcV3yTaPZ5E | https://explorer.solana.com/address/7sF2JumHpWiPjS3XtnQ8cKraTzzfcGSvQHcV3yTaPZ5E |
+------------+----------------------------------------------+----------------------------------------------------------------------------------+


Python


Work in progress

Java


Work in progress

Swift


Work in progress

React


This package contains a set of useful React hooks to help you build your perfect dApp. If you are interested in a hook that is not included in this package please open an issue to let us know!

npm i @bonfida/sns-react
yarn add @bonfida/sns-react

Vue


This package contains a set of useful Vue composables to help you build your perfect dApp. If you are interested in a composable that is not included in this package please open an issue to let us know!

npm i @bonfida/sns-vue
yarn add @bonfida/sns-vue

Demo app with an example of each composable usage.


Examples



Resolving a domain


The following examples show how to resolve the domain bonfida.sol:

  1. With the JS SDK
const connection = new Connection(clusterApiUrl("mainnet-beta"));
const owner = await resolve(connection, "bonfida");
expect(owner.toBase58()).toBe("HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA");
  1. With the Rust SDK
let client = RpcClient::new(std::env::var("RPC_URL").unwrap());
let res = resolve_owner(&client, "bonfida").await.unwrap();
assert_eq!(res, pubkey!("HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA"));
  1. With the CLI
$ sns resolve bonfida

+---------+----------------------------------------------+----------------------------------------------------------------------------------+
| Domain  | Owner                                        | Explorer                                                                         |
+---------+----------------------------------------------+----------------------------------------------------------------------------------+
| bonfida | HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA | https://explorer.solana.com/address/HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA |
+---------+----------------------------------------------+----------------------------------------------------------------------------------+
  1. With the Cloudflare worker
GET https://sns-sdk-proxy.bonfida.workers.dev/resolve/bonfida
{ "s": "ok", "result": "HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA" }
  1. With the React SDK
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
import { useDomainOwner, useDomainsForOwner } from "@bonfida/sns-react";

export const Example = () => {
  const { connection } = useConnection();
  const { publicKey, connected } = useWallet();
  const { result } = useDomainOwner(connection, "bonfida");
  // ...
};

Bounties


Feature Description In progress Completed Bounty
Golang Translate JS SDK into a robust, well-tested Golang SDK; high-quality code essential โŒ โŒ โœ…
Python Translate JS SDK into a robust, well-tested Python SDK; high-quality code essential โŒ โŒ โœ…
Java Translate JS SDK into a robust, well-tested Java SDK; high-quality code essential โŒ โŒ โœ…
Swift Translate JS SDK into a robust, well-tested Swift SDK; high-quality code essential โŒ โŒ โœ…

If you have any questions or suggestions, feel free to open an issue or pull request, or simply contact us at @bonfida. We're always here for a good chat about Solana and the decentralized web!

sns-sdk's People

Contributors

akashrdev avatar dr497 avatar ellttben avatar letehaha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sns-sdk's Issues

Not able to pull latest rust sns-sdk library

I'm using sns-sdk = "1.2.0" inside my project and getting this error when trying to import sns-sdk

Log:

rust-analyzer failed to load workspace: Failed to load the project at /GitHub/api/Cargo.toml: Failed to read Cargo metadata from Cargo.toml file /GitHub/api/Cargo.toml, Some(Version { major: 1, minor: 71, patch: 0 }): Failed to run `cd "/GitHub/api" && "cargo" "metadata" "--format-version" "1" "--manifest-path" "/GitHub/api/Cargo.toml" "--filter-platform" "aarch64-apple-darwin"`: `cargo metadata` exited with an error:     Updating crates.io index
error: failed to select a version for `curve25519-dalek`.
    ... required by package `solana-program v1.14.18`
    ... which satisfies dependency `solana-program = "=1.14.18"` of package `solana-address-lookup-table-program v1.14.18`
    ... which satisfies dependency `solana-address-lookup-table-program = "=1.14.18"` of package `solana-account-decoder v1.14.18`
    ... which satisfies dependency `solana-account-decoder = "=1.14.18"` of package `solana-client v1.14.18`
    ... which satisfies dependency `solana-client = "^1.14.18"` of package `sns-sdk v1.2.0`
    ... which satisfies dependency `sns-sdk = "^1.2.0"` of package `name_resolver v1.0.0 (/GitHub/api/name_resolver)`
    ... which satisfies path dependency `name_resolver` (locked to 1.0.0) of package `client v1.0.0 (/GitHub/api/client)`
versions that meet the requirements `^3.2.1` are: 3.2.1

all possible versions conflict with previously selected packages.

  previously selected package `curve25519-dalek v3.0.0`
    ... which satisfies dependency `curve25519-dalek = "^3"` of package `ed25519-dalek v1.0.1`
    ... which satisfies dependency `ed25519-dalek = "^1.0.1"` of package `sns-sdk v1.2.0`
    ... which satisfies dependency `sns-sdk = "^1.2.0"` of package `name_resolver v1.0.0 (/GitHub/api/name_resolver)`
    ... which satisfies path dependency `name_resolver` (locked to 1.0.0) of package `client v1.0.0 (/GitHub/api/client)`

failed to select a version for `curve25519-dalek` which could resolve this conflict

Minor: console.logs() left in built version

When running unit tests:

  console.log
    mint Avcptd1yzx67NnK8ed8g8HZGeg8vFZp6437cwSm3gQj6

      at F (node_modules/@bonfida/spl-name-service/dist/index.cjs:1:8742)

  console.log
    mint 6sLbLpia2LuH8jNyfgc1EEjeZkCTDmsfujhmzunkwnZ3

      at F (node_modules/@bonfida/spl-name-service/dist/index.cjs:1:8742)

  console.log
    mint 4QdW7gKBvYkfyGndoq2LJ4uJRAgdDFrgV336zdd86nDW

      at F (node_modules/@bonfida/spl-name-service/dist/index.cjs:1:8742)

  console.log
    mint 6sLbLpia2LuH8jNyfgc1EEjeZkCTDmsfujhmzunkwnZ3

      at F (node_modules/@bonfida/spl-name-service/dist/index.cjs:1:8742)

I can't find this in your code (searching for mint doesn't find anything so maybe you just need to rebuild.

Error: Signature verification failed

I am going to make the script to transfer the domain
but I have "Error: Signature verification failed" issue
Please help me to fix this issue
this is my current code

const { pubkey } = await getDomainKey(domain_sol);
let anotherKeypair = Keypair.generate();

// Step 2
// The registry object contains all the info about the domain name
// The NFT owner is of type PublicKey | undefined
const { registry, nftOwner } = await NameRegistryState.retrieve(
  connection,
  pubkey
);
const newOwner = new PublicKey(phantomWalletDestinatiob);

const ix = await transferNameOwnership(
  connection,
  domain_sol,
  newOwner,
  wallet.publicKey,
  registry.class,
  registry.parentName
);
const tx = new Transaction();
tx.add(ix)
tx.feePayer = wallet.publicKey;
tx.recentBlockhash =(await connection.getRecentBlockhash('max')).blockhash;
// await tx.setSigners(wallet.publicKey, anotherKeypair.publicKey);
// await tx.partialSign(anotherKeypair)
console.log(tx)
const result = await sendAndConfirmTransaction (
  connection,
  tx,
  [wallet]
)

[BUG] Results with Errors

I tried to use the @bonfida/spl-name-service package and tried running the example given in here

const connection = new Connection(clusterApiUrl("mainnet-beta"));
const owner = await resolve(connection, "bonfida");
expect(owner.toBase58()).toBe("HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA");

This runs but there is a error logged in the console as shown below

node index.js
Error: Invalid name account provided
    at G.retrieve (/Users/aadhi/Documents/github/bonfida-trial/node_modules/@bonfida/spl-name-service/dist/index.cjs:1:9672)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ue (/Users/aadhi/Documents/github/bonfida-trial/node_modules/@bonfida/spl-name-service/dist/index.cjs:1:15017)
    at async pe (/Users/aadhi/Documents/github/bonfida-trial/node_modules/@bonfida/spl-name-service/dist/index.cjs:1:15166)
    at async exports.resolve (/Users/aadhi/Documents/github/bonfida-trial/node_modules/@bonfida/spl-name-service/dist/index.cjs:1:23924)
    at async main (/Users/aadhi/Documents/github/bonfida-trial/index.js:11:17)
{
  owner: PublicKey [PublicKey(HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA)] {
    _bn: <BN: f26cb7227020209c2da674948f8f3c330ee4f9a386256bd14f37a6e0c567542b>
  }
} HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA

Looks like this is thrown from here

sns-sdk/js/src/utils.ts

Lines 151 to 161 in e0f96e2

export const getDomainKeySync = (domain: string, record = false) => {
if (domain.endsWith(".sol")) {
domain = domain.slice(0, -4);
}
const splitted = domain.split(".");
if (splitted.length === 2) {
const prefix = Buffer.from([record ? 1 : 0]).toString();
const sub = prefix.concat(splitted[0]);
const { pubkey: parentKey } = _deriveSync(splitted[1]);
const result = _deriveSync(sub, parentKey);
return { ...result, isSub: true, parent: parentKey };

Specifically the line

const result = _deriveSync(sub, parentKey);

produces a pubkey that doesn't exists.

sub however is \x01SOL which indeed matches with what is given in this guide

What could be causing the problem here? Can you please help me out?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.