Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/0.18.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
vsund committed Apr 16, 2018
2 parents 6f7faa6 + 76da4ff commit 56383dc
Show file tree
Hide file tree
Showing 26 changed files with 1,071 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
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
43 changes: 43 additions & 0 deletions .gitignore
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 added .npmignore
Empty file.
25 changes: 25 additions & 0 deletions LICENSE.md
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.
21 changes: 21 additions & 0 deletions README.md
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).
21 changes: 21 additions & 0 deletions package.json
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"
}
}
156 changes: 156 additions & 0 deletions src/BlockstackCoreClient.ts
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);
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { BlockstackCoreClient } from './BlockstackCoreClient';
11 changes: 11 additions & 0 deletions src/responses/AuthRequestResponse.json
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"
]
}
9 changes: 9 additions & 0 deletions src/responses/GetAllNamesResponse.json
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})$"
}
}
10 changes: 10 additions & 0 deletions src/responses/GetAllNamespacesResponse.json
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" }
}
}
}
11 changes: 11 additions & 0 deletions src/responses/GetConsensusHashResponse.json
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}$"
}
}
}
18 changes: 18 additions & 0 deletions src/responses/GetHistoricalZoneFileResponse.json
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" }
}
}
]
}
Loading

0 comments on commit 56383dc

Please sign in to comment.