This repository has been archived by the owner on Dec 11, 2020. It is now read-only.
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
0 parents
commit 5fce785
Showing
27 changed files
with
1,003 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 helps developers define and maintain consistent coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
# We recommend you to keep these unchanged | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,3 @@ | ||
package-lock.json | ||
node_modules/ | ||
typings/ |
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,14 @@ | ||
{ | ||
"editor.tabSize": 2, | ||
"editor.insertSpaces": true, | ||
"files.eol": "\n", | ||
"files.trimTrailingWhitespace": true, | ||
"files.exclude": { | ||
"**/.git": true, | ||
"**/package-lock.json": true | ||
}, | ||
"search.exclude":{ | ||
"**/node_modules": true | ||
}, | ||
"tslint.enable": true | ||
} |
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,12 @@ | ||
import * as model from '../model/Account'; | ||
import { Http } from '../services/Http'; | ||
|
||
export class AccountApi { | ||
|
||
constructor(private http: Http) {} | ||
|
||
get(params: model.AccountQueryParams) { | ||
return this.http.get('/accounts', params, model.AccountResponse); | ||
} | ||
|
||
} |
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,28 @@ | ||
import { Http } from '../services/Http'; | ||
import * as model from '../model/models'; | ||
|
||
import { AccountApi } from './AccountApi'; | ||
import { DelegateApi } from './DelegateApi'; | ||
import { PeerApi } from './PeerApi'; | ||
import { LoaderApi } from './LoaderApi'; | ||
import { BlockApi } from './BlockApi'; | ||
|
||
export class Api { | ||
|
||
public account: AccountApi; | ||
public delegate: DelegateApi; | ||
public peer: PeerApi; | ||
public loader: LoaderApi; | ||
public block: BlockApi; | ||
|
||
constructor(network: model.Network) { | ||
var request = new Http(network); | ||
|
||
this.account = new AccountApi(request); | ||
this.delegate = new DelegateApi(request); | ||
this.peer = new PeerApi(request); | ||
this.loader = new LoaderApi(request); | ||
this.block = new BlockApi(request); | ||
} | ||
|
||
} |
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,24 @@ | ||
import * as model from '../model/Block'; | ||
import { Http } from '../services/Http'; | ||
|
||
export class BlockApi { | ||
|
||
constructor(private http: Http) {} | ||
|
||
get(params: model.BlockQueryParams) { | ||
return this.http.get('/blocks/get', params, model.BlockResponse); | ||
} | ||
|
||
list(params?: model.BlockQueryParams) { | ||
return this.http.get('/blocks', params, model.BlockResponse); | ||
} | ||
|
||
blockchainFee() { | ||
return this.http.get('/blocks', null, model.BlockFee); | ||
} | ||
|
||
blockchainHeight() { | ||
return this.http.get('/blocks', null, model.BlockHeight); | ||
} | ||
|
||
} |
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,35 @@ | ||
import * as model from '../model/Delegate'; | ||
import { Http } from '../services/Http'; | ||
|
||
export class DelegateApi { | ||
|
||
constructor(private http: Http) {} | ||
|
||
get(params: model.DelegateQueryParams) { | ||
return this.http.get('/delegates/get', params, model.DelegateResponse); | ||
} | ||
|
||
list(params?: model.DelegateQueryParams) { | ||
return this.http.get('/delegates', params, model.DelegateResponse); | ||
} | ||
|
||
voters(params: model.DelegateQueryParams) { | ||
/* To find voters directly by model */ | ||
if (params.delegate && params.delegate instanceof model.Delegate) | ||
params = {publicKey: params.delegate.publicKey} | ||
|
||
return this.http.get('/delegates/voters', params, model.DelegateVoters); | ||
} | ||
|
||
forgedData(params: model.DelegateQueryParams) { | ||
/* To find result directly by model */ | ||
if (params.delegate) | ||
params.generatorPublicKey = params.delegate.publicKey | ||
|
||
if (params.publicKey && !params.generatorPublicKey) | ||
params.generatorPublicKey = params.publicKey | ||
|
||
return this.http.get('/delegates/forging/getForgedByAccount', params, model.ForgedDetails); | ||
} | ||
|
||
} |
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,16 @@ | ||
import * as model from '../model/Loader'; | ||
import { Http } from '../services/Http'; | ||
|
||
export class LoaderApi { | ||
|
||
constructor(private http: Http) {} | ||
|
||
loadingStatus() { | ||
return this.http.get('/loader/status', null, model.LoaderStatus); | ||
} | ||
|
||
synchronisationStatus() { | ||
return this.http.get('/loader/status/sync', null, model.LoaderStatusSync); | ||
} | ||
|
||
} |
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,16 @@ | ||
import * as model from '../model/Peer'; | ||
import { Http } from '../services/Http'; | ||
|
||
export class PeerApi { | ||
|
||
constructor(private http: Http) {} | ||
|
||
public get(params: model.PeerQueryParams) { | ||
return this.http.get('/peers/get', params, model.PeerResponse); | ||
} | ||
|
||
public list(params?: model.PeerQueryParams) { | ||
return this.http.get('/peers', params, model.PeerResponse); | ||
} | ||
|
||
} |
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,13 @@ | ||
import * as model from '../model/Transaction'; | ||
import { Http } from '../services/Http'; | ||
|
||
export class TransactionApi { | ||
|
||
constructor(private http: Http) {} | ||
|
||
send(params: model.TransactionSend) { | ||
return this.http.get('/accounts', params, model.TransactionResponse); | ||
} | ||
|
||
vote() {} | ||
} |
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,35 @@ | ||
export default { | ||
"networks": { | ||
"mainnet": { | ||
"name": "mainnet", | ||
"nethash": "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988", | ||
"token": "ARK", | ||
"symbol": "Ѧ", | ||
"version": 0x17, | ||
"explorer": "https://explorer.ark.io", | ||
"wif": 0xaa, | ||
"activePeer": { | ||
"ip": "node1.arknet.cloud", | ||
"port": 4001 | ||
} | ||
}, | ||
"devnet": { | ||
"name": "devnet", | ||
"nethash": "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988", | ||
"token": "DEVARK", | ||
"symbol": "DѦ", | ||
"version": 0x82, | ||
"explorer": "https://dexplorer.arkcoin.net", | ||
"wif": 0xba, | ||
"activePeer": { | ||
"ip": "164.8.251.179", | ||
"port": 4002 | ||
} | ||
} | ||
}, | ||
"blockchain": { | ||
"interval": 8, | ||
"delegates": 51, | ||
"date": new Date(Date.UTC(2017,2,21,13,0,0,0)) | ||
} | ||
} |
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,85 @@ | ||
import * as secp256k1 from 'secp256k1'; | ||
import * as bs58check from 'bs58check'; | ||
|
||
import { Crypto } from '../utils/Crypto'; | ||
import { Network } from '../model/Network'; | ||
|
||
/* Throw new error based on condition */ | ||
function assert(condition: boolean, message: string) { | ||
if (!condition) | ||
throw new Error(message || "Assertion failed"); | ||
} | ||
|
||
interface PublicKey { | ||
publicKey: Buffer, | ||
isCompressed: boolean, | ||
network: Network | ||
} | ||
|
||
interface PrivateKey { | ||
privateKey: Buffer, | ||
publicKey: PublicKey | ||
} | ||
|
||
export class Key { | ||
|
||
/* Return public and private key */ | ||
static getKeys(passphrase: string, network?: Network) { | ||
var privateKey = this.getPrivateKey(passphrase); | ||
var publicKey = this.getPublicKey(privateKey); | ||
if (!network) network = new Network().getDefault(); // mainnet | ||
|
||
var pub = <PublicKey>{ | ||
publicKey: publicKey, | ||
isCompressed: true, | ||
network: network | ||
} | ||
|
||
var pri = <PrivateKey>{ | ||
privateKey: privateKey, | ||
publicKey: pub | ||
} | ||
|
||
return pri; | ||
} | ||
|
||
/* Return public key from 32-byte private key. */ | ||
static getPublicKey(privateKey: Buffer):Buffer { | ||
assert(privateKey.length === 32, "Bad private key"); | ||
var compressed = secp256k1.publicKeyCreate(privateKey); | ||
|
||
return secp256k1.publicKeyConvert(compressed, true); | ||
} | ||
|
||
/* Return 32-byte private key from passphrase */ | ||
static getPrivateKey(passphrase: string):Buffer { | ||
var hash = Crypto.sha256(new Buffer(passphrase, 'utf-8')); | ||
|
||
return hash; | ||
} | ||
|
||
/* Return address from publicKey */ | ||
static getAddress(pub: PublicKey):string { | ||
var payload = new Buffer(21); | ||
var hash = Crypto.ripemd160(pub.publicKey); | ||
var version = pub.network.version; | ||
|
||
payload.writeUInt8(version, 0); | ||
hash.copy(payload, 1); | ||
|
||
return bs58check.encode(payload); | ||
} | ||
|
||
/* Create an ECDSA signature */ | ||
static sign(hash: Buffer, pri: PrivateKey):Buffer { | ||
var sig = secp256k1.sign(hash, pri.privateKey).signature; | ||
return secp256k1.signatureExport(sig); | ||
} | ||
|
||
/* Verify an ECDSA signature. */ | ||
static verify(signature: Buffer, data: Buffer, pub: PublicKey):boolean { | ||
var sig = secp256k1.signatureImport(signature); | ||
return secp256k1.verify(data, sig, pub.publicKey); | ||
} | ||
|
||
} |
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 @@ | ||
import { Key } from './core/Key'; | ||
import { Network, NetworkType } from './model/Network'; | ||
|
||
var keys = Key.getKeys('ark typescripted', new Network().getDefault(NetworkType.Devnet)); | ||
var address = Key.getAddress(keys.publicKey); | ||
|
||
var hash = new Buffer(32); | ||
var signature = Key.sign(hash, keys); | ||
var verify = Key.verify(signature, hash, keys.publicKey); | ||
|
||
console.log(verify); |
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,56 @@ | ||
import * as model from './models'; | ||
import { JsonObject, JsonMember } from 'typedjson-npm'; | ||
|
||
@JsonObject | ||
export class Account { | ||
@JsonMember({ type: String }) | ||
address: string; | ||
|
||
@JsonMember({ type: String }) | ||
unconfirmedBalance: string; | ||
|
||
@JsonMember({ type: String }) | ||
balance: string; | ||
|
||
@JsonMember({ type: String }) | ||
publicKey: string; | ||
|
||
@JsonMember({ type: Number }) | ||
unconfirmedSignature: number; | ||
|
||
@JsonMember({ type: Number }) | ||
secondSignature: number; | ||
|
||
@JsonMember({ type: Object }) | ||
secondPublicKey: Object; | ||
|
||
@JsonMember({ elements: Object, refersAbstractType: true }) | ||
multiSignatures: Array<Object>; | ||
|
||
@JsonMember({ elements: Object, refersAbstractType: true }) | ||
uMultiSignatures: Array<Object>; | ||
} | ||
|
||
@JsonObject | ||
export class AccountResponse { | ||
@JsonMember({ type: Boolean }) | ||
success: boolean; | ||
|
||
@JsonMember({ type: Account }) | ||
account: Account; | ||
} | ||
|
||
@JsonObject | ||
export class AccountVotesResponse { | ||
@JsonMember({ type: Boolean }) | ||
success: boolean; | ||
|
||
@JsonMember({ elements: Object, refersAbstractType: true }) | ||
delegates: Array<model.Delegate>; | ||
} | ||
|
||
@JsonObject | ||
export class AccountQueryParams { | ||
@JsonMember({ type: String }) | ||
address: string; | ||
} |
Oops, something went wrong.