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

feat(sdk): resolve slashtag from dns human readable address #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ A collection of examples that demonstrate how to use the Slashtags SDK.
At the root directory of this monorepo, run `npm install`

If you made any changes to this monorepo during devolpment, make sure to run `npm run link` at the root directory, and clean the temporary storage directory by running `npm run clean` in this directory.

## Examples

Available examples and their purpose:

- [auth](./auth/) Demonstrates Auth protocol.
- [drives/watch](./drives/wathc/) Demonstrates watching live updates to a remote drive.
- [dns](./drives/) Demonstrates resolving a Slashtag key from a DNS address.
- [primaryKey](./primaryKey/) Demonstrates generating a primaryKey from a mnemonic seed.
23 changes: 23 additions & 0 deletions examples/dns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Slashtags Address

Demonstrates retrieving a Slashtag from DNS based human readable address like `[email protected]`.

## Usage

Run server side:

```bash
npm run serve
```

Resolve the Slashtag profile from `alice@localhost:9999`

```bash
npm run fetch
```

Or for root level address `localhost:9999`

```bash
npm run fetch localhost:9999
```
17 changes: 17 additions & 0 deletions examples/dns/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SDK } from '@synonymdev/slashtags-sdk'
import fetch from 'node-fetch'

const address = process.argv[2] || 'alice@localhost:9999'

const sdk = await SDK.init({ persist: false })

const slashtag = await sdk.fromDNS(address, {
protocol: 'http://',
fetch
})

const profile = await slashtag.getProfile()

console.log('Resolved profile', profile)

sdk.close()
7 changes: 7 additions & 0 deletions examples/dns/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "module",
"scripts": {
"serve": "node server.js",
"fetch": "node client.js"
}
}
27 changes: 27 additions & 0 deletions examples/dns/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import http from 'http'
import { SDK } from '@synonymdev/slashtags-sdk'

const sdk = await SDK.init({ persist: false })

const alice = sdk.slashtag({ name: 'alice' })
await alice.setProfile({ name: 'Alice' })

const root = sdk.slashtag({ name: 'root' })
await root.setProfile({ name: 'Root' })

const server = http.createServer((req, res) => {
if (!req.url.startsWith('/.well-known/slashtags')) return

res.setHeader('Content-Type', 'application/json')
res.setHeader('Access-Control-Allow-Origin', '*')
res.end(
JSON.stringify({
_: root.url,
alice: alice.url
})
)
})

server.listen(9999, () => {
console.log('Server listening on localhost:' + 9999)
})
Loading