-
Notifications
You must be signed in to change notification settings - Fork 4
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
30 changed files
with
2,409 additions
and
2,623 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,46 @@ | ||
import { NetworkType, PublicAccount } from 'nem2-sdk'; | ||
import { map, reduce, shareReplay } from 'rxjs/operators'; | ||
import { ApostilleHttp } from './../src/infrastructure/ApostilleHttp'; | ||
import { HistoricalEndpoints } from './../src/model/repository/HistoricalEndpoints'; | ||
|
||
// const accountLarge = PublicAccount.createFromPublicKey( | ||
// 'FE9F2C724D0E0360A20B9ED7591E4E25CF25D6F4A4E8E52C491C62D2452397F8', | ||
// NetworkType.MIJIN_TEST); | ||
|
||
// const accountSmall = PublicAccount.createFromPublicKey( | ||
// '38FD27361DB3B12953AF6C3813F740ADB7C980789DCB3D2486B3B654CBC91B72', | ||
// NetworkType.MIJIN_TEST); | ||
const accountSmall = PublicAccount.createFromPublicKey( | ||
'95361ED8C94048BD5B0BDB229C19DF817DB7D66B59F4162E3F3A1D0D813B2AB9', | ||
NetworkType.MIJIN_TEST); | ||
|
||
const http = new ApostilleHttp(HistoricalEndpoints[NetworkType.MIJIN_TEST]); | ||
|
||
const subscription = http.fetchAllTransactions(accountSmall).pipe( | ||
map((txs) => { | ||
return txs.map((tx) => { | ||
if (!tx.transactionInfo) { return {}; } | ||
console.log(tx.transactionInfo.id, tx.transactionInfo.height.compact()); | ||
return { | ||
height: tx.transactionInfo.height, | ||
id: tx.transactionInfo.id, | ||
}; | ||
}); | ||
}), | ||
reduce((acc, txs) => { | ||
return acc.concat(txs); | ||
}), | ||
shareReplay(), | ||
); | ||
|
||
subscription.subscribe((txs) => { | ||
console.log('First', txs.length); | ||
}); | ||
subscription.subscribe((txs) => { | ||
console.log('Second', txs.length); | ||
}); | ||
setTimeout(() => { | ||
subscription.subscribe((txs) => { | ||
console.log('Third', txs.length); | ||
}); | ||
}, 10000); |
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,82 @@ | ||
import fs from 'fs'; | ||
import { Account, NetworkType, PublicAccount, SignedTransaction } from 'nem2-sdk'; | ||
import path from 'path'; | ||
import { Apostille, ApostilleHttp, HistoricalEndpoints, Initiator, SHA256, SHA3_256 } from '../index'; | ||
|
||
// ApostilleHttp | ||
const network = NetworkType.MIJIN_TEST; | ||
const apostilleHttp = new ApostilleHttp(HistoricalEndpoints[network]); | ||
|
||
// Create Apostille function | ||
function createApostille(pk, fileName) { | ||
const file = fs.readFileSync(`${path.basename(__dirname)}/${fileName}`); | ||
const fileData = file.toString('hex'); | ||
|
||
// Account info | ||
const generatorAccount = Account.createFromPrivateKey(pk, network); | ||
|
||
// FOR DEMO PURPOSES ONLY - DO NOT USE IN PRODUCTION! | ||
const sinkPublicKey = SHA256.hash('PublicApostilleSinkAddress'); | ||
const sinkAddress = PublicAccount.createFromPublicKey(sinkPublicKey, network).address; | ||
|
||
// Create apostille | ||
const apostille = Apostille.initFromSeed(fileName, generatorAccount); | ||
|
||
const fileHash = new SHA3_256().signedHashing(fileData, pk, network); | ||
|
||
console.log(fileHash); | ||
|
||
const apostilleTx = apostille.update(fileHash); | ||
apostilleHttp.addTransaction({ | ||
initiator: new Initiator(generatorAccount), | ||
transaction: apostilleTx, | ||
}); | ||
|
||
const sinkTx = apostille.update(fileHash, sinkAddress); | ||
apostilleHttp.addTransaction({ | ||
initiator: new Initiator(apostille.HDAccount), | ||
transaction: sinkTx, | ||
}); | ||
|
||
const multisigTx = apostille.associate([generatorAccount.publicAccount], 1, 1); | ||
apostilleHttp.addTransaction(multisigTx); | ||
|
||
const metadata = { | ||
filename: fileName, | ||
tags: ['apostille', 'sample', 'LuxTag'], | ||
// tslint:disable-next-line:object-literal-sort-keys | ||
description: 'LuxTag logo', | ||
originFileURL: 'https://luxtag.io/wp-content/uploads/2018/04/logo-Luxtag-uai-720x269.png', | ||
}; | ||
const metadataTx = apostille.update(JSON.stringify(metadata)); | ||
apostilleHttp.addTransaction({ | ||
initiator: new Initiator(generatorAccount), | ||
transaction: metadataTx, | ||
}); | ||
} | ||
|
||
// File info | ||
const f = 'luxtag1.png'; | ||
const accounts = [ | ||
'aaaaaaaaaaeeeeeeeeeebbbbbbbbbb5555555555dddddddddd1111111111aae1', | ||
'aaaaaaaaaaeeeeeeeeeebbbbbbbbbb5555555555dddddddddd1111111111aae2', | ||
'aaaaaaaaaaeeeeeeeeeebbbbbbbbbb5555555555dddddddddd1111111111aae3', | ||
'aaaaaaaaaaeeeeeeeeeebbbbbbbbbb5555555555dddddddddd1111111111aae4', | ||
'aaaaaaaaaaeeeeeeeeeebbbbbbbbbb5555555555dddddddddd1111111111aae5', | ||
'aaaaaaaaaaeeeeeeeeeebbbbbbbbbb5555555555dddddddddd1111111111aae6', | ||
'aaaaaaaaaaeeeeeeeeeebbbbbbbbbb5555555555dddddddddd1111111111aae7', | ||
]; | ||
|
||
accounts.forEach((a) => createApostille(a, f)); | ||
|
||
// Announce | ||
apostilleHttp.announceAll().subscribe( | ||
(result) => { | ||
if (result instanceof Array) { | ||
if (result[0] instanceof SignedTransaction) { | ||
return; | ||
} | ||
} | ||
console.log(result); | ||
}, | ||
); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -42,41 +42,44 @@ | |
{ | ||
"name": "jeff", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Jonathan Tey", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"@octokit/request": "^2.1.2", | ||
"crypto-js": "^3.1.9-1", | ||
"js-sha3": "0.8.0", | ||
"js-sha3": "^0.8.0", | ||
"lodash": "^4.17.10", | ||
"nem-sdk": "^1.6.7", | ||
"nem2-sdk": "^0.11.1", | ||
"nem2-sdk": "^0.13.1", | ||
"rxjs": "^6.2.2" | ||
}, | ||
"devDependencies": { | ||
"@types/crypto-js": "^3.1.43", | ||
"@types/jest": "^23.3.9", | ||
"@types/jest": "24.0.11", | ||
"@types/lodash": "^4.14.113", | ||
"@types/sinon": "5.0.7", | ||
"@types/sinon": "7.0.11", | ||
"codecov": "^3.0.4", | ||
"commitizen": "3.0.4", | ||
"commitlint": "7.2.1", | ||
"commitizen": "3.0.7", | ||
"commitlint": "7.5.2", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"ghooks": "^2.0.4", | ||
"jest": "^23.4.1", | ||
"npm-run-all": "4.1.5", | ||
"rimraf": "^2.6.2", | ||
"semantic-release": "^15.8.1", | ||
"sinon": "7.1.1", | ||
"travis-deploy-once": "5.0.9", | ||
"ts-jest": "^23.0.1", | ||
"sinon": "7.3.1", | ||
"travis-deploy-once": "5.0.11", | ||
"ts-jest": "24.0.2", | ||
"tslint": "^5.11.0", | ||
"typescript": "^2.8.3", | ||
"typescript": "3.4.3", | ||
"validate-commit-msg": "^2.14.0" | ||
}, | ||
"resolutions": { | ||
"@octokit/request": "^2.1.2" | ||
"request": "2.88.0" | ||
}, | ||
"files": [ | ||
"dist" | ||
|
@@ -92,24 +95,23 @@ | |
}, | ||
"jest": { | ||
"testEnvironment": "node", | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"preset": "ts-jest", | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(tsx?)$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"jsx", | ||
"json", | ||
"node" | ||
"jsx", | ||
"node", | ||
"ts", | ||
"tsx" | ||
], | ||
"coverageDirectory": "<rootDir>/tests/unit/coverage", | ||
"collectCoverageFrom": [ | ||
"<rootDir>/src/**/*.ts" | ||
], | ||
"coveragePathIgnorePatterns": [ | ||
"/types/" | ||
] | ||
], | ||
"testMatch": null | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.