This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,071 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[{package.json,yarn.lock,*.yml}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Custom | ||
dist/ | ||
src/**/*.js | ||
src/responses/*d.ts |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
The MIT License (MIT) | ||
===================== | ||
|
||
Copyright © 2018 ntzwrk.org | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the “Software”), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# blockstack-core-client.ts | ||
|
||
|
||
## About | ||
This is a dead simple JavaScript / TypeScript implementation of the API endpoints of [Blockstack Core](https://github.com/blockstack/blockstack-core). | ||
|
||
The version number is supposed to be the same as the one for Blockstack Core. | ||
|
||
|
||
## Installation | ||
Simply install it with `yarn install blockstack-core-client.ts` into your project. | ||
|
||
|
||
## Usage | ||
Since this project doesn't add much complexity, there's currently no more usage information. | ||
|
||
If you want to know more about the API endpoints of Blockstack Core, see [here](https://blockstack.github.io/blockstack-core/). Otherwise see [`src/BlockstackCoreClient.ts`](https://github.com/ntzwrk/blockstack-core-client.ts/blob/master/src/BlockstackCoreClient.ts) or your favorite auto-completion for the respective method names. | ||
|
||
|
||
## License | ||
This code is published under the [MIT License](https://github.com/ntzwrk/blockstack-core-client.ts/blob/master/LICENSE.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "blockstack-core-client.ts", | ||
"version": "0.18.0", | ||
"author": { | ||
"name": "vsund" | ||
}, | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"license": "MIT", | ||
"scripts": { | ||
"generate-json-interfaces": "cd ./src/responses/ && find ./ -name \"*.json\" -exec json2ts --style.useTabs --style.singleQuote --input {} --output {}.d.ts \\; && cd -", | ||
"build": "yarn run clean && yarn run generate-json-interfaces && tsc && cp -r ./src/responses ./dist/responses", | ||
"clean": "rm -rf ./dist/ && rm -r ./src/responses/*.d.ts" | ||
}, | ||
"dependencies": { | ||
"@types/node-fetch": "^1.6.8", | ||
"json-schema-to-typescript": "^5.4.0", | ||
"node-fetch": "^2.1.2", | ||
"typescript": "^2.8.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import fetch from 'node-fetch'; | ||
import { | ||
AuthRequestResponseJson, | ||
GetAllNamespacesResponseJson, | ||
GetAllNamesResponseJson, | ||
GetConsensusHashResponseJson, | ||
GetHistoricalZoneFileResponseJson, | ||
GetNameHistoryResponseJson, | ||
GetNameInfoResponseJson, | ||
GetNamePriceResponseJson, | ||
GetNamesOwnedByAddressResponseJson, | ||
GetNamespaceNamesResponseJson, | ||
GetNamespacePriceResponseJson, | ||
GetNumberOfNamesOnBlockchainResponseJson, | ||
GetOperationsInBlockResponseJson, | ||
GetZoneFileResponseJson, | ||
PingResponseJson | ||
} from './responses'; | ||
|
||
|
||
export class BlockstackCoreClient { | ||
public readonly host: string; | ||
public readonly port: number; | ||
public readonly scheme: string; | ||
public readonly basePath: string; | ||
|
||
constructor(host: string, port: number = 443, scheme: string = 'https', basePath: string = '') { | ||
this.host = host; | ||
this.port = port; | ||
this.scheme = scheme; | ||
this.basePath = basePath; | ||
} | ||
|
||
private async fetchEndpoint<T>(path: string): Promise<T> { | ||
const response = await fetch(`${this.scheme}://${this.host}${this.basePath}${path}`); | ||
|
||
let data; | ||
try { | ||
data = (await response.json()) as T; | ||
} catch (error) { | ||
throw error; | ||
} | ||
|
||
return data; | ||
} | ||
|
||
|
||
/* | ||
* Authorization | ||
*/ | ||
|
||
public async requestAuth(authRequestToken: string) { | ||
const path = `/auth?authRequest=${authRequestToken}`; | ||
return this.fetchEndpoint<AuthRequestResponseJson>(path); | ||
} | ||
|
||
|
||
/* | ||
* Core Node Administration | ||
*/ | ||
|
||
public async ping() { | ||
const path = '/v1/node/ping'; | ||
return this.fetchEndpoint<PingResponseJson>(path); | ||
} | ||
|
||
|
||
/* | ||
* Managing Names | ||
*/ | ||
|
||
public async getZoneFile(name: string) { | ||
const path = `/v1/names/${name}/zonefile`; | ||
return this.fetchEndpoint<GetZoneFileResponseJson>(path); | ||
} | ||
|
||
|
||
/* | ||
* Name Querying | ||
*/ | ||
|
||
public async getAllNames(page: number) { | ||
const path = `/v1/names?page=${page}`; | ||
return this.fetchEndpoint<GetAllNamesResponseJson>(path); | ||
} | ||
|
||
public async getNameInfo(name: string) { | ||
const path = `/v1/names/${name}`; | ||
return this.fetchEndpoint<GetNameInfoResponseJson>(path); | ||
} | ||
|
||
public async getNameHistory(name: string) { | ||
const path = `/v1/names/${name}/history`; | ||
return this.fetchEndpoint<GetNameHistoryResponseJson>(path); | ||
} | ||
|
||
public async getHistoricalZoneFile(name: string, zoneFileHash: string) { | ||
const path = `/v1/names/${name}/zonefile/${zoneFileHash}`; | ||
return this.fetchEndpoint<GetHistoricalZoneFileResponseJson>(path); | ||
} | ||
|
||
public async getNamesOwnedByAddress(blockchain: string, address: string) { | ||
const path = `/v1/addresses/${blockchain}/${address}`; | ||
return this.fetchEndpoint<GetNamesOwnedByAddressResponseJson>(path); | ||
} | ||
|
||
|
||
/* | ||
* Price Checks | ||
*/ | ||
|
||
public async getNamespacePrice(tld: string) { | ||
const path = `/v1/prices/namespaces/${tld}`; | ||
return this.fetchEndpoint<GetNamespacePriceResponseJson>(path); | ||
} | ||
|
||
public async getNamePrice(name: string) { | ||
const path = `/v1/prices/names/${name}`; | ||
return this.fetchEndpoint<GetNamePriceResponseJson>(path); | ||
} | ||
|
||
|
||
/* | ||
* Blockchain Operations | ||
*/ | ||
|
||
public async getConsensusHash(blockchainName: string) { | ||
const path = `/v1/blockchains/${blockchainName}/consensus`; | ||
return this.fetchEndpoint<GetConsensusHashResponseJson>(path); | ||
} | ||
|
||
public async getNumberOfNamesOnBlockchain(blockchainName: string) { | ||
const path = `/v1/blockchains/${blockchainName}/name_count`; | ||
return this.fetchEndpoint<GetNumberOfNamesOnBlockchainResponseJson>(path); | ||
} | ||
|
||
public async getOperationsInBlock(blockchainName: string, blockHeight: number) { | ||
const path = `/v1/blockchains/${blockchainName}/operations/${blockHeight}`; | ||
return this.fetchEndpoint<GetOperationsInBlockResponseJson>(path); | ||
} | ||
|
||
|
||
/* | ||
* Namespace Operations | ||
*/ | ||
|
||
public async getAllNamespaces() { | ||
const path = '/v1/namespaces'; | ||
return this.fetchEndpoint<GetAllNamespacesResponseJson>(path); | ||
} | ||
|
||
public async getNamespaceNames(tld: string, page: number) { | ||
const path = `/v1/namespaces/${tld}/names?page=${page}`; | ||
return this.fetchEndpoint<GetNamespaceNamesResponseJson>(path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { BlockstackCoreClient } from './BlockstackCoreClient'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema#", | ||
"id": "AuthRequestResponse.json", | ||
"type": "object", | ||
"properties": { | ||
"token": { "type": "string" } | ||
}, | ||
"required": [ | ||
"token" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema#", | ||
"id": "GetAllNamesResponse.json", | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"pattern": "^([a-z0-9\\-_.+]{3,37})$" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema#", | ||
"id": "GetAllNamespacesResponse.json", | ||
"properties": { | ||
"namespaces": { | ||
"type": "array", | ||
"items": { "type": "string" } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema#", | ||
"id": "GetConsensusHashResponse.json", | ||
"type": "object", | ||
"properties": { | ||
"consensus_hash": { | ||
"type": "string", | ||
"pattern": "^[0-9a-fA-F]{32}$" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema#", | ||
"id": "GetHistoricalZoneFileResponse.json", | ||
"anyOf": [ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"zonefile": { "type": "string" } | ||
} | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"error": { "type": "string" } | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.