Comparing version 1.6.0 to 1.7.0
@@ -16,2 +16,3 @@ import Ar from "./ar"; | ||
export interface CreateTransactionInterface { | ||
format: number; | ||
last_tx: string; | ||
@@ -23,2 +24,4 @@ owner: string; | ||
data: string | Uint8Array; | ||
data_size: string; | ||
data_root?: string; | ||
reward: string; | ||
@@ -33,6 +36,10 @@ } | ||
silo: Silo; | ||
crypto: CryptoInterface; | ||
utils: typeof ArweaveUtils; | ||
static init: (apiConfig: ApiConfig) => Arweave; | ||
constructor(config: Config); | ||
static crypto: CryptoInterface; | ||
static utils: typeof ArweaveUtils; | ||
constructor(apiConfig: ApiConfig); | ||
/** @deprecated */ | ||
readonly crypto: CryptoInterface; | ||
/** @deprecated */ | ||
readonly utils: typeof ArweaveUtils; | ||
getConfig(): Config; | ||
@@ -39,0 +46,0 @@ createTransaction(attributes: Partial<CreateTransactionInterface>, jwk: JWKInterface): Promise<Transaction>; |
@@ -9,15 +9,22 @@ "use strict"; | ||
const transaction_1 = require("./lib/transaction"); | ||
const Merkle = require("./lib/merkle"); | ||
const ArweaveUtils = require("./lib/utils"); | ||
const silo_1 = require("./silo"); | ||
class Arweave { | ||
constructor(config) { | ||
this.crypto = config.crypto; | ||
this.api = new api_1.default(config.api); | ||
this.wallets = new wallets_1.default(this.api, config.crypto); | ||
this.transactions = new transactions_1.default(this.api, config.crypto); | ||
constructor(apiConfig) { | ||
this.api = new api_1.default(apiConfig); | ||
this.wallets = new wallets_1.default(this.api, Arweave.crypto); | ||
this.transactions = new transactions_1.default(this.api, Arweave.crypto); | ||
this.silo = new silo_1.default(this.api, this.crypto, this.transactions); | ||
this.network = new network_1.default(this.api); | ||
this.ar = new ar_1.default(); | ||
this.utils = ArweaveUtils; | ||
} | ||
/** @deprecated */ | ||
get crypto() { | ||
return Arweave.crypto; | ||
} | ||
/** @deprecated */ | ||
get utils() { | ||
return Arweave.utils; | ||
} | ||
getConfig() { | ||
@@ -53,2 +60,5 @@ return { | ||
if (attributes.data) { | ||
const rootHash = await Merkle.computeRootHash(attributes.data); | ||
transaction.data_size = attributes.data.byteLength.toString(); | ||
transaction.data_root = ArweaveUtils.bufferTob64Url(rootHash); | ||
transaction.data = ArweaveUtils.bufferTob64Url(attributes.data); | ||
@@ -97,3 +107,4 @@ } | ||
} | ||
Arweave.utils = ArweaveUtils; | ||
exports.default = Arweave; | ||
//# sourceMappingURL=common.js.map |
"use strict"; | ||
const common_1 = require("./common"); | ||
const node_driver_1 = require("./lib/crypto/node-driver"); | ||
common_1.default.crypto = new node_driver_1.default(); | ||
common_1.default.init = function (apiConfig = {}) { | ||
return new common_1.default({ | ||
api: apiConfig, | ||
crypto: new node_driver_1.default() | ||
}); | ||
return new common_1.default(apiConfig); | ||
}; | ||
module.exports = common_1.default; | ||
//# sourceMappingURL=index.js.map |
@@ -57,3 +57,4 @@ "use strict"; | ||
baseURL: `${this.config.protocol}://${this.config.host}:${this.config.port}`, | ||
timeout: this.config.timeout | ||
timeout: this.config.timeout, | ||
maxContentLength: 1024 * 1024 * 512 | ||
}); | ||
@@ -60,0 +61,0 @@ if (this.config.logging) { |
@@ -8,3 +8,3 @@ import { JWKInterface } from "../wallet"; | ||
decrypt(encrypted: Uint8Array, key: string | Uint8Array): Promise<Uint8Array>; | ||
hash(data: Uint8Array): Promise<Uint8Array>; | ||
hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>; | ||
} |
@@ -12,3 +12,3 @@ /// <reference types="node" /> | ||
verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>; | ||
hash(data: Buffer): Promise<Uint8Array>; | ||
hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>; | ||
/** | ||
@@ -34,2 +34,3 @@ * If a key is passed as a buffer it *must* be exactly 32 bytes. | ||
private pemToJWK; | ||
private parseHashAlgorithm; | ||
} |
@@ -64,6 +64,6 @@ "use strict"; | ||
} | ||
hash(data) { | ||
hash(data, algorithm = "SHA-256") { | ||
return new Promise((resolve, reject) => { | ||
resolve(crypto | ||
.createHash(this.hashAlgorithm) | ||
.createHash(this.parseHashAlgorithm(algorithm)) | ||
.update(data) | ||
@@ -123,4 +123,14 @@ .digest()); | ||
} | ||
parseHashAlgorithm(algorithm) { | ||
switch (algorithm) { | ||
case "SHA-256": | ||
return "sha256"; | ||
case "SHA-384": | ||
return "sha384"; | ||
default: | ||
throw new Error(`Algorithm not supported: ${algorithm}`); | ||
} | ||
} | ||
} | ||
exports.default = NodeCryptoDriver; | ||
//# sourceMappingURL=node-driver.js.map |
@@ -12,3 +12,3 @@ /// <reference types="node" /> | ||
sign(jwk: JWKInterface, data: Uint8Array): Promise<Uint8Array>; | ||
hash(data: Uint8Array): Promise<Uint8Array>; | ||
hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>; | ||
verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>; | ||
@@ -15,0 +15,0 @@ private jwkToCryptoKey; |
@@ -43,4 +43,4 @@ "use strict"; | ||
} | ||
async hash(data) { | ||
let digest = await this.driver.digest("SHA-256", data); | ||
async hash(data, algorithm = "SHA-256") { | ||
let digest = await this.driver.digest(algorithm, data); | ||
return new Uint8Array(digest); | ||
@@ -47,0 +47,0 @@ } |
@@ -19,2 +19,3 @@ declare class BaseObject { | ||
export interface TransactionInterface { | ||
format: number; | ||
id: string; | ||
@@ -29,4 +30,8 @@ last_tx: string; | ||
signature: string; | ||
data_size: string; | ||
data_root: string; | ||
data_tree: string[]; | ||
} | ||
export default class Transaction extends BaseObject implements TransactionInterface { | ||
readonly format: number; | ||
id: string; | ||
@@ -39,2 +44,5 @@ readonly last_tx: string; | ||
readonly data: string; | ||
readonly data_size: string; | ||
readonly data_root: string; | ||
readonly data_tree: string[]; | ||
readonly reward: string; | ||
@@ -45,2 +53,3 @@ signature: string; | ||
toJSON(): { | ||
format: number; | ||
id: string; | ||
@@ -53,2 +62,5 @@ last_tx: string; | ||
data: string; | ||
data_size: string; | ||
data_root: string; | ||
data_tree: string[]; | ||
reward: string; | ||
@@ -61,4 +73,4 @@ signature: string; | ||
}): void; | ||
getSignatureData(): Uint8Array; | ||
getSignatureData(): Promise<Uint8Array>; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ArweaveUtils = require("./utils"); | ||
const deepHash_1 = require("./deepHash"); | ||
class BaseObject { | ||
@@ -29,2 +30,3 @@ get(field, options) { | ||
super(); | ||
this.format = 2; | ||
this.id = ""; | ||
@@ -37,2 +39,5 @@ this.last_tx = ""; | ||
this.data = ""; | ||
this.data_size = "0"; | ||
this.data_root = ""; | ||
this.data_tree = []; | ||
this.reward = "0"; | ||
@@ -52,2 +57,3 @@ this.signature = ""; | ||
return { | ||
format: this.format, | ||
id: this.id, | ||
@@ -60,4 +66,7 @@ last_tx: this.last_tx, | ||
data: this.data, | ||
data_size: this.data_size, | ||
data_root: this.data_root, | ||
data_tree: this.data_tree, | ||
reward: this.reward, | ||
signature: this.signature | ||
signature: this.signature, | ||
}; | ||
@@ -69,17 +78,38 @@ } | ||
} | ||
getSignatureData() { | ||
let tagString = this.tags.reduce((accumulator, tag) => { | ||
return (accumulator + | ||
tag.get("name", { decode: true, string: true }) + | ||
tag.get("value", { decode: true, string: true })); | ||
}, ""); | ||
return ArweaveUtils.concatBuffers([ | ||
this.get("owner", { decode: true, string: false }), | ||
this.get("target", { decode: true, string: false }), | ||
this.get("data", { decode: true, string: false }), | ||
ArweaveUtils.stringToBuffer(this.quantity), | ||
ArweaveUtils.stringToBuffer(this.reward), | ||
this.get("last_tx", { decode: true, string: false }), | ||
ArweaveUtils.stringToBuffer(tagString) | ||
]); | ||
async getSignatureData() { | ||
switch (this.format) { | ||
case 1: | ||
let tagString = this.tags.reduce((accumulator, tag) => { | ||
return (accumulator + | ||
tag.get("name", { decode: true, string: true }) + | ||
tag.get("value", { decode: true, string: true })); | ||
}, ""); | ||
return ArweaveUtils.concatBuffers([ | ||
this.get("owner", { decode: true, string: false }), | ||
this.get("target", { decode: true, string: false }), | ||
this.get("data", { decode: true, string: false }), | ||
ArweaveUtils.stringToBuffer(this.quantity), | ||
ArweaveUtils.stringToBuffer(this.reward), | ||
this.get("last_tx", { decode: true, string: false }), | ||
ArweaveUtils.stringToBuffer(tagString), | ||
]); | ||
case 2: | ||
const tagList = this.tags.map((tag) => [ | ||
tag.get("name", { decode: true, string: false }), | ||
tag.get("value", { decode: true, string: false }), | ||
]); | ||
return await deepHash_1.default([ | ||
ArweaveUtils.stringToBuffer(this.format.toString()), | ||
this.get("owner", { decode: true, string: false }), | ||
this.get("target", { decode: true, string: false }), | ||
ArweaveUtils.stringToBuffer(this.quantity), | ||
ArweaveUtils.stringToBuffer(this.reward), | ||
this.get("last_tx", { decode: true, string: false }), | ||
tagList, | ||
ArweaveUtils.stringToBuffer(this.data_size), | ||
this.get("data_root", { decode: true, string: false }), | ||
]); | ||
default: | ||
throw new Error(`Unexpected transaction format: ${this.format}`); | ||
} | ||
} | ||
@@ -86,0 +116,0 @@ } |
@@ -42,3 +42,6 @@ "use strict"; | ||
if (response.status == 200 && response.data && response.data.id == id) { | ||
return new transaction_1.default(response.data); | ||
if (response.data.format) { | ||
return new transaction_1.default(response.data); | ||
} | ||
return new transaction_1.default(Object.assign({}, response.data, { format: 1 })); | ||
} | ||
@@ -104,3 +107,3 @@ if (response.status == 202) { | ||
async sign(transaction, jwk) { | ||
let dataToSign = transaction.getSignatureData(); | ||
let dataToSign = await transaction.getSignatureData(); | ||
let rawSignature = await this.crypto.sign(jwk, dataToSign); | ||
@@ -114,3 +117,3 @@ let id = await this.crypto.hash(rawSignature); | ||
async verify(transaction) { | ||
const signaturePayload = transaction.getSignatureData(); | ||
const signaturePayload = await transaction.getSignatureData(); | ||
/** | ||
@@ -117,0 +120,0 @@ * The transaction ID should be a SHA-256 hash of the raw signature bytes, so this needs |
{ | ||
"name": "arweave", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Arweave JS client library", | ||
@@ -26,3 +26,4 @@ "main": "index.js", | ||
"test:web": "npm run bundle:web && npx webpack --config-name web-tests && open test/web/web.html", | ||
"prettier:check": "prettier --check 'src/**/*.ts' 'test/**/*.ts'" | ||
"prettier:check": "prettier --check 'src/**/*.ts' 'test/**/*.ts'", | ||
"prettier:write": "prettier --write 'src/**/*.ts' 'test/**/*.ts'" | ||
}, | ||
@@ -65,3 +66,3 @@ "repository": { | ||
"webpack-bundle-analyzer": "^3.3.2", | ||
"webpack-cli": "^3.3.2" | ||
"webpack-cli": "^3.3.11" | ||
}, | ||
@@ -68,0 +69,0 @@ "targets": { |
102
README.md
@@ -198,10 +198,16 @@ # Arweave JS | ||
// Transaction { | ||
// last_tx: '', | ||
// owner: 'wgfbaaSXJ8dszMabPo-...', | ||
// format: 2, | ||
// id: 'ReUohI9tEmXQ6EN9H9IkRjY9bSdgql_OdLUCOeMEte0', | ||
// last_tx: 'Tk-0c7260Ya5zjfjzl4f6-W-vRO94qiqZMAScKBcYXc68v1Pd8bYfTbKWi7pepUF', | ||
// owner: 'kmM4O08BJB85RbxfQ2nkka9VNO6Czm2Tc_IGQNYCTSXRzO...', | ||
// tags: [], | ||
// target: '', | ||
// quantity: '0', | ||
// data: 'eyJhIjoxfQ', | ||
// reward: '321879995', | ||
// signature: '' } | ||
// data: 'c29tZSBkYXRh', | ||
// data_size: '9', | ||
// data_root: 'qwKZUl7qWpCEmB3cpONKTYOcSmnmhb-_s8ggMTZwCU4', | ||
// data_tree: [], | ||
// reward: '7489274', | ||
// signature: 'JYdFPblDuT95ky7_wVss3Ax9e4Qygcd_lEcB07sDPUD_wNslOk...' | ||
// } | ||
``` | ||
@@ -222,4 +228,6 @@ | ||
// Transaction { | ||
// last_tx: '', | ||
// owner: '14fXfoRDMFS5yTpUT7ODzj...', | ||
// format: 2, | ||
// id: 'v-n7hAc7cubeXSClh0beaOs1RjYFagyvpl2TkUOfbRg', | ||
// last_tx: 'Tk-0c7260Ya5zjfjzl4f6-W-vRO94qiqZMAScKBcYXc68v1Pd8bYfTbKWi7pepUF', | ||
// owner: 'kmM4O08BJB85RbxfQ2nkka9VNO6Czm2Tc_IGQNYCTSXRzOc6W9b...', | ||
// tags: [], | ||
@@ -229,4 +237,8 @@ // target: '1seRanklLU_1VTGkEk7P0xAwMJfA7owA1JHW5KyZKlY', | ||
// data: '', | ||
// reward: '2503211 | ||
// signature: '' } | ||
// data_size: '0', | ||
// data_root: '', | ||
// data_tree: [], | ||
// reward: '7468335', | ||
// signature: 'DnUOYbRSkhI4ZXg5fpYDCwPv8yvM5toAneSx4Jlg0zjIocqPs8giPP...' | ||
// } | ||
``` | ||
@@ -255,13 +267,19 @@ | ||
// Transaction { | ||
// last_tx: '', | ||
// owner: 's8zPWNlBMiJFLcvpH98QxnI6FoPar3vCK3RdT...', | ||
// format: 2, | ||
// id: 'dUaZG84fJpiPQTt4J1VMBGvAr2ugyevFf0zmdkC1Ch4', | ||
// last_tx: 'Tk-0c7260Ya5zjfjzl4f6-W-vRO94qiqZMAScKBcYXc68v1Pd8bYfTbKWi7pepUF', | ||
// owner: 'kmM4O08BJB85RbxfQ2nkka9VNO6Czm2Tc_IGQNYC...', | ||
// tags: [ | ||
// Tag { name: 'Q29udGVudC1UeXBl', value: 'dGV4dC9odG1s' }, | ||
// Tag { name: 'a2V5Mg', value: 'dmFsdWUy' } | ||
// Tag { name: 'Q29udGVudC1UeXBl', value: 'dGV4dC9odG1s' }, | ||
// Tag { name: 'a2V5Mg', value: 'dmFsdWUy' } | ||
// ], | ||
// target: '', | ||
// quantity: '0', | ||
// data: 'PGh0bWw-PGhlYWQ-PG1ldGEgY2hh...', | ||
// reward: '329989175', | ||
// signature: '' } | ||
// data: 'PGh0bWw-PGhlYWQ-PG1ldGEgY2hhcnNldD0iVVRGLTgiPjx0aXRsZT5IZWxsbyB3b3JsZCE8L3RpdGxlPjwvaGVhZD48Ym9keT48L2JvZHk-PC9odG1sPg', | ||
// data_size: '88', | ||
// data_root: 'GQunzmbwk2_JPU7oJOmLrTMvj8v_7BJaF0weyjVn5Nc', | ||
// data_tree: [], | ||
// reward: '7673074', | ||
// signature: 'JhioDyYS76tkfCqoRUfqvy-GW1tn3abARX0q8Fo_SRygCq...' | ||
// } | ||
``` | ||
@@ -282,6 +300,7 @@ | ||
console.log(transaction); | ||
// Signature and id fields are now populated | ||
// Transaction { | ||
// last_tx: '', | ||
// owner: '2xu89EaA5zENRRsbOh4OscMcy...', | ||
// format: 2, | ||
// id: 'v-n7hAc7cubeXSClh0beaOs1RjYFagyvpl2TkUOfbRg', | ||
// last_tx: 'Tk-0c7260Ya5zjfjzl4f6-W-vRO94qiqZMAScKBcYXc68v1Pd8bYfTbKWi7pepUF', | ||
// owner: 'kmM4O08BJB85RbxfQ2nkka9VNO6Czm2Tc_IGQNYCTSXRzOc6W9b...', | ||
// tags: [], | ||
@@ -291,5 +310,8 @@ // target: '1seRanklLU_1VTGkEk7P0xAwMJfA7owA1JHW5KyZKlY', | ||
// data: '', | ||
// reward: '250321179212', | ||
// signature: 'AbFjlpEHTN6_SKWsUSMAzalImOVxNm86Z8hoTZcItkYBJLx...' | ||
// id: 'iHVHijWvKbIa0ZA9IbuKtOxJdNO9qyey6CIH324zQWI' | ||
// data_size: '0', | ||
// data_root: '', | ||
// data_tree: [], | ||
// reward: '7468335', | ||
// signature: 'DnUOYbRSkhI4ZXg5fpYDCwPv8yvM5toAneSx4Jlg0zjIocqPs8giPP...' | ||
// } | ||
``` | ||
@@ -333,18 +355,24 @@ | ||
```js | ||
const transaction = arweave.transactions.get('bNbA3TEQVL60xlgCcqdz4ZPHFZ711cZ3hmkpGttDt_U').then(transaction => { | ||
const transaction = arweave.transactions.get('hKMMPNh_emBf8v_at1tFzNYACisyMQNcKzeeE1QE9p8').then(transaction => { | ||
console.log(transaction); | ||
// Transaction { | ||
// last_tx: 'cO5gl_d5ARnaoBtu2Vas8skgLg-6KnC9gH8duWP7Ll8', | ||
// owner: 'pJjRtSRLpHUVAKCtWC9pjajI_VEpiPEEAHX0k...', | ||
// tags: [ | ||
// Tag { name: 'Q29udGVudC1UeXBl', value: 'dGV4dC9odG1s' }, | ||
// Tag { name: 'VXNlci1BZ2VudA', value: 'QXJ3ZWF2ZURlcGxveS8xLjEuMA' } | ||
// ], | ||
// target: '', | ||
// quantity: '0', | ||
// data: 'CjwhRE9DVFlQRSBodG1sPgo8aHRtbCBsYW5nPSJlbiI...', | ||
// reward: '1577006493', | ||
// signature: 'NLiRQSci56KVNk-x86eLT1TyF1ST8pzE...', | ||
// id: 'bNbA3TEQVL60xlgCcqdz4ZPHFZ711cZ3hmkpGttDt_U' } | ||
// }) | ||
// Transaction { | ||
// 'format': 1, | ||
// 'id': 'hKMMPNh_emBf8v_at1tFzNYACisyMQNcKzeeE1QE9p8', | ||
// 'last_tx': 'GW7p6NoGJ495tAoUjU5GLxIH52gqOgk5j78gQv3j0ebvldAlw6VgIUv_lrMNGI72', | ||
// 'owner': 'warLaSbicZm1nx9ucf-_5i91CWgmNOcnFJfyJdloCtsbenBhLrcGH472kKTZyuEAp2lSKlZ0NFCT2r2z-0...', | ||
// 'tags': [ | ||
// { | ||
// 'name': 'QXBwLU5hbWU', | ||
// 'value': 'd2VpYm90LXNlYXJjaC13ZWlicw' | ||
// } | ||
// ], | ||
// 'target': ', | ||
// 'quantity': '0', | ||
// 'data': 'iVBORw0KGgoAAAANSUhEUgAAArIAAADGCAYAAAAuVWN-AAAACXBIWXMAAAsSAAA...' | ||
// 'data_size': '36795', | ||
// 'data_tree': [], | ||
// 'data_root': ', | ||
// 'reward': '93077980', | ||
// 'signature': 'RpohCHVl5vzGlG4R5ybeEuhs556Jv7rWOGaZCT69cpIei_j9b9sAetBlr0...' | ||
// } | ||
}); | ||
@@ -351,0 +379,0 @@ ``` |
@@ -16,2 +16,3 @@ import Ar from "./ar"; | ||
export interface CreateTransactionInterface { | ||
format: number; | ||
last_tx: string; | ||
@@ -23,2 +24,4 @@ owner: string; | ||
data: string | Uint8Array; | ||
data_size: string; | ||
data_root?: string; | ||
reward: string; | ||
@@ -33,6 +36,10 @@ } | ||
silo: Silo; | ||
crypto: CryptoInterface; | ||
utils: typeof ArweaveUtils; | ||
static init: (apiConfig: ApiConfig) => Arweave; | ||
constructor(config: Config); | ||
static crypto: CryptoInterface; | ||
static utils: typeof ArweaveUtils; | ||
constructor(apiConfig: ApiConfig); | ||
/** @deprecated */ | ||
readonly crypto: CryptoInterface; | ||
/** @deprecated */ | ||
readonly utils: typeof ArweaveUtils; | ||
getConfig(): Config; | ||
@@ -39,0 +46,0 @@ createTransaction(attributes: Partial<CreateTransactionInterface>, jwk: JWKInterface): Promise<Transaction>; |
@@ -9,15 +9,22 @@ "use strict"; | ||
const transaction_1 = require("./lib/transaction"); | ||
const Merkle = require("./lib/merkle"); | ||
const ArweaveUtils = require("./lib/utils"); | ||
const silo_1 = require("./silo"); | ||
class Arweave { | ||
constructor(config) { | ||
this.crypto = config.crypto; | ||
this.api = new api_1.default(config.api); | ||
this.wallets = new wallets_1.default(this.api, config.crypto); | ||
this.transactions = new transactions_1.default(this.api, config.crypto); | ||
constructor(apiConfig) { | ||
this.api = new api_1.default(apiConfig); | ||
this.wallets = new wallets_1.default(this.api, Arweave.crypto); | ||
this.transactions = new transactions_1.default(this.api, Arweave.crypto); | ||
this.silo = new silo_1.default(this.api, this.crypto, this.transactions); | ||
this.network = new network_1.default(this.api); | ||
this.ar = new ar_1.default(); | ||
this.utils = ArweaveUtils; | ||
} | ||
/** @deprecated */ | ||
get crypto() { | ||
return Arweave.crypto; | ||
} | ||
/** @deprecated */ | ||
get utils() { | ||
return Arweave.utils; | ||
} | ||
getConfig() { | ||
@@ -53,2 +60,5 @@ return { | ||
if (attributes.data) { | ||
const rootHash = await Merkle.computeRootHash(attributes.data); | ||
transaction.data_size = attributes.data.byteLength.toString(); | ||
transaction.data_root = ArweaveUtils.bufferTob64Url(rootHash); | ||
transaction.data = ArweaveUtils.bufferTob64Url(attributes.data); | ||
@@ -97,3 +107,4 @@ } | ||
} | ||
Arweave.utils = ArweaveUtils; | ||
exports.default = Arweave; | ||
//# sourceMappingURL=common.js.map |
@@ -8,2 +8,3 @@ "use strict"; | ||
const webcrypto_driver_1 = require("./lib/crypto/webcrypto-driver"); | ||
common_1.default.crypto = new webcrypto_driver_1.default(); | ||
common_1.default.init = function (apiConfig = {}) { | ||
@@ -47,8 +48,5 @@ function getDefaultConfig() { | ||
const port = apiConfig.port || defaultConfig.port; | ||
return new common_1.default({ | ||
api: Object.assign({}, apiConfig, { host, | ||
protocol, | ||
port }), | ||
crypto: new webcrypto_driver_1.default() | ||
}); | ||
return new common_1.default(Object.assign({}, apiConfig, { host, | ||
protocol, | ||
port })); | ||
}; | ||
@@ -55,0 +53,0 @@ window.Arweave = common_1.default; |
@@ -57,3 +57,4 @@ "use strict"; | ||
baseURL: `${this.config.protocol}://${this.config.host}:${this.config.port}`, | ||
timeout: this.config.timeout | ||
timeout: this.config.timeout, | ||
maxContentLength: 1024 * 1024 * 512 | ||
}); | ||
@@ -60,0 +61,0 @@ if (this.config.logging) { |
@@ -8,3 +8,3 @@ import { JWKInterface } from "../wallet"; | ||
decrypt(encrypted: Uint8Array, key: string | Uint8Array): Promise<Uint8Array>; | ||
hash(data: Uint8Array): Promise<Uint8Array>; | ||
hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>; | ||
} |
@@ -12,3 +12,3 @@ /// <reference types="node" /> | ||
verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>; | ||
hash(data: Buffer): Promise<Uint8Array>; | ||
hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>; | ||
/** | ||
@@ -34,2 +34,3 @@ * If a key is passed as a buffer it *must* be exactly 32 bytes. | ||
private pemToJWK; | ||
private parseHashAlgorithm; | ||
} |
@@ -64,6 +64,6 @@ "use strict"; | ||
} | ||
hash(data) { | ||
hash(data, algorithm = "SHA-256") { | ||
return new Promise((resolve, reject) => { | ||
resolve(crypto | ||
.createHash(this.hashAlgorithm) | ||
.createHash(this.parseHashAlgorithm(algorithm)) | ||
.update(data) | ||
@@ -123,4 +123,14 @@ .digest()); | ||
} | ||
parseHashAlgorithm(algorithm) { | ||
switch (algorithm) { | ||
case "SHA-256": | ||
return "sha256"; | ||
case "SHA-384": | ||
return "sha384"; | ||
default: | ||
throw new Error(`Algorithm not supported: ${algorithm}`); | ||
} | ||
} | ||
} | ||
exports.default = NodeCryptoDriver; | ||
//# sourceMappingURL=node-driver.js.map |
@@ -12,3 +12,3 @@ /// <reference types="node" /> | ||
sign(jwk: JWKInterface, data: Uint8Array): Promise<Uint8Array>; | ||
hash(data: Uint8Array): Promise<Uint8Array>; | ||
hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>; | ||
verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>; | ||
@@ -15,0 +15,0 @@ private jwkToCryptoKey; |
@@ -43,4 +43,4 @@ "use strict"; | ||
} | ||
async hash(data) { | ||
let digest = await this.driver.digest("SHA-256", data); | ||
async hash(data, algorithm = "SHA-256") { | ||
let digest = await this.driver.digest(algorithm, data); | ||
return new Uint8Array(digest); | ||
@@ -47,0 +47,0 @@ } |
@@ -19,2 +19,3 @@ declare class BaseObject { | ||
export interface TransactionInterface { | ||
format: number; | ||
id: string; | ||
@@ -29,4 +30,8 @@ last_tx: string; | ||
signature: string; | ||
data_size: string; | ||
data_root: string; | ||
data_tree: string[]; | ||
} | ||
export default class Transaction extends BaseObject implements TransactionInterface { | ||
readonly format: number; | ||
id: string; | ||
@@ -39,2 +44,5 @@ readonly last_tx: string; | ||
readonly data: string; | ||
readonly data_size: string; | ||
readonly data_root: string; | ||
readonly data_tree: string[]; | ||
readonly reward: string; | ||
@@ -45,2 +53,3 @@ signature: string; | ||
toJSON(): { | ||
format: number; | ||
id: string; | ||
@@ -53,2 +62,5 @@ last_tx: string; | ||
data: string; | ||
data_size: string; | ||
data_root: string; | ||
data_tree: string[]; | ||
reward: string; | ||
@@ -61,4 +73,4 @@ signature: string; | ||
}): void; | ||
getSignatureData(): Uint8Array; | ||
getSignatureData(): Promise<Uint8Array>; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ArweaveUtils = require("./utils"); | ||
const deepHash_1 = require("./deepHash"); | ||
class BaseObject { | ||
@@ -29,2 +30,3 @@ get(field, options) { | ||
super(); | ||
this.format = 2; | ||
this.id = ""; | ||
@@ -37,2 +39,5 @@ this.last_tx = ""; | ||
this.data = ""; | ||
this.data_size = "0"; | ||
this.data_root = ""; | ||
this.data_tree = []; | ||
this.reward = "0"; | ||
@@ -52,2 +57,3 @@ this.signature = ""; | ||
return { | ||
format: this.format, | ||
id: this.id, | ||
@@ -60,4 +66,7 @@ last_tx: this.last_tx, | ||
data: this.data, | ||
data_size: this.data_size, | ||
data_root: this.data_root, | ||
data_tree: this.data_tree, | ||
reward: this.reward, | ||
signature: this.signature | ||
signature: this.signature, | ||
}; | ||
@@ -69,17 +78,38 @@ } | ||
} | ||
getSignatureData() { | ||
let tagString = this.tags.reduce((accumulator, tag) => { | ||
return (accumulator + | ||
tag.get("name", { decode: true, string: true }) + | ||
tag.get("value", { decode: true, string: true })); | ||
}, ""); | ||
return ArweaveUtils.concatBuffers([ | ||
this.get("owner", { decode: true, string: false }), | ||
this.get("target", { decode: true, string: false }), | ||
this.get("data", { decode: true, string: false }), | ||
ArweaveUtils.stringToBuffer(this.quantity), | ||
ArweaveUtils.stringToBuffer(this.reward), | ||
this.get("last_tx", { decode: true, string: false }), | ||
ArweaveUtils.stringToBuffer(tagString) | ||
]); | ||
async getSignatureData() { | ||
switch (this.format) { | ||
case 1: | ||
let tagString = this.tags.reduce((accumulator, tag) => { | ||
return (accumulator + | ||
tag.get("name", { decode: true, string: true }) + | ||
tag.get("value", { decode: true, string: true })); | ||
}, ""); | ||
return ArweaveUtils.concatBuffers([ | ||
this.get("owner", { decode: true, string: false }), | ||
this.get("target", { decode: true, string: false }), | ||
this.get("data", { decode: true, string: false }), | ||
ArweaveUtils.stringToBuffer(this.quantity), | ||
ArweaveUtils.stringToBuffer(this.reward), | ||
this.get("last_tx", { decode: true, string: false }), | ||
ArweaveUtils.stringToBuffer(tagString), | ||
]); | ||
case 2: | ||
const tagList = this.tags.map((tag) => [ | ||
tag.get("name", { decode: true, string: false }), | ||
tag.get("value", { decode: true, string: false }), | ||
]); | ||
return await deepHash_1.default([ | ||
ArweaveUtils.stringToBuffer(this.format.toString()), | ||
this.get("owner", { decode: true, string: false }), | ||
this.get("target", { decode: true, string: false }), | ||
ArweaveUtils.stringToBuffer(this.quantity), | ||
ArweaveUtils.stringToBuffer(this.reward), | ||
this.get("last_tx", { decode: true, string: false }), | ||
tagList, | ||
ArweaveUtils.stringToBuffer(this.data_size), | ||
this.get("data_root", { decode: true, string: false }), | ||
]); | ||
default: | ||
throw new Error(`Unexpected transaction format: ${this.format}`); | ||
} | ||
} | ||
@@ -86,0 +116,0 @@ } |
@@ -42,3 +42,6 @@ "use strict"; | ||
if (response.status == 200 && response.data && response.data.id == id) { | ||
return new transaction_1.default(response.data); | ||
if (response.data.format) { | ||
return new transaction_1.default(response.data); | ||
} | ||
return new transaction_1.default(Object.assign({}, response.data, { format: 1 })); | ||
} | ||
@@ -104,3 +107,3 @@ if (response.status == 202) { | ||
async sign(transaction, jwk) { | ||
let dataToSign = transaction.getSignatureData(); | ||
let dataToSign = await transaction.getSignatureData(); | ||
let rawSignature = await this.crypto.sign(jwk, dataToSign); | ||
@@ -114,3 +117,3 @@ let id = await this.crypto.hash(rawSignature); | ||
async verify(transaction) { | ||
const signaturePayload = transaction.getSignatureData(); | ||
const signaturePayload = await transaction.getSignatureData(); | ||
/** | ||
@@ -117,0 +120,0 @@ * The transaction ID should be a SHA-256 hash of the raw signature bytes, so this needs |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
847646
112
9182
476