Comparing version 1.10.1 to 1.10.2
import { JWKInterface } from "../wallet"; | ||
export interface SignatureOptions { | ||
saltLength?: number; | ||
} | ||
export default interface CryptoInterface { | ||
generateJWK(): Promise<JWKInterface>; | ||
sign(jwk: JWKInterface, data: Uint8Array, options?: SignatureOptions): Promise<Uint8Array>; | ||
sign(jwk: JWKInterface, data: Uint8Array): Promise<Uint8Array>; | ||
verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>; | ||
@@ -9,0 +6,0 @@ encrypt(data: Uint8Array, key: string | Uint8Array): Promise<Uint8Array>; |
/// <reference types="node" /> | ||
import { JWKInterface } from "../wallet"; | ||
import CryptoInterface, { SignatureOptions } from "./crypto-interface"; | ||
import CryptoInterface from "./crypto-interface"; | ||
export default class NodeCryptoDriver implements CryptoInterface { | ||
@@ -10,3 +10,3 @@ readonly keyLength = 4096; | ||
generateJWK(): Promise<JWKInterface>; | ||
sign(jwk: object, data: Uint8Array, { saltLength }?: SignatureOptions): Promise<Uint8Array>; | ||
sign(jwk: object, data: Uint8Array): Promise<Uint8Array>; | ||
verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>; | ||
@@ -13,0 +13,0 @@ hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>; |
@@ -34,3 +34,3 @@ "use strict"; | ||
} | ||
sign(jwk, data, { saltLength } = {}) { | ||
sign(jwk, data) { | ||
return new Promise((resolve, reject) => { | ||
@@ -43,3 +43,3 @@ resolve(crypto | ||
padding: constants.RSA_PKCS1_PSS_PADDING, | ||
saltLength, | ||
saltLength: 0 | ||
})); | ||
@@ -62,2 +62,3 @@ }); | ||
padding: constants.RSA_PKCS1_PSS_PADDING, | ||
saltLength: 0 | ||
}, signature)); | ||
@@ -64,0 +65,0 @@ }); |
/// <reference types="node" /> | ||
import { JWKInterface } from "../wallet"; | ||
import CryptoInterface, { SignatureOptions } from "./crypto-interface"; | ||
import CryptoInterface from "./crypto-interface"; | ||
export default class WebCryptoDriver implements CryptoInterface { | ||
@@ -11,3 +11,3 @@ readonly keyLength = 4096; | ||
generateJWK(): Promise<JWKInterface>; | ||
sign(jwk: JWKInterface, data: Uint8Array, { saltLength }?: SignatureOptions): Promise<Uint8Array>; | ||
sign(jwk: JWKInterface, data: Uint8Array): Promise<Uint8Array>; | ||
hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>; | ||
@@ -14,0 +14,0 @@ verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>; |
@@ -12,3 +12,3 @@ "use strict"; | ||
} | ||
this.driver = crypto.subtle; | ||
this.driver = window.crypto.subtle; | ||
} | ||
@@ -37,6 +37,6 @@ async generateJWK() { | ||
} | ||
async sign(jwk, data, { saltLength } = {}) { | ||
async sign(jwk, data) { | ||
let signature = await this.driver.sign({ | ||
name: "RSA-PSS", | ||
saltLength | ||
saltLength: 0 | ||
}, await this.jwkToCryptoKey(jwk), data); | ||
@@ -58,2 +58,3 @@ return new Uint8Array(signature); | ||
name: "RSA-PSS", | ||
saltLength: 0 | ||
}, key, signature, data); | ||
@@ -78,17 +79,22 @@ } | ||
detectWebCrypto() { | ||
if (typeof crypto === "undefined") { | ||
if (!window || !window.crypto || !window.crypto.subtle) { | ||
return false; | ||
} | ||
const subtle = crypto === null || crypto === void 0 ? void 0 : crypto.subtle; | ||
if (subtle === undefined) { | ||
let subtle = window.crypto.subtle; | ||
if (typeof subtle.generateKey != "function") { | ||
return false; | ||
} | ||
const names = [ | ||
"generateKey", | ||
"importKey", | ||
"exportKey", | ||
"digest", | ||
"sign", | ||
]; | ||
return names.every((name) => typeof subtle[name] === "function"); | ||
if (typeof subtle.importKey != "function") { | ||
return false; | ||
} | ||
if (typeof subtle.exportKey != "function") { | ||
return false; | ||
} | ||
if (typeof subtle.digest != "function") { | ||
return false; | ||
} | ||
if (typeof subtle.sign != "function") { | ||
return false; | ||
} | ||
return true; | ||
} | ||
@@ -95,0 +101,0 @@ async encrypt(data, key) { |
@@ -132,9 +132,7 @@ "use strict"; | ||
case 1: | ||
let tags = this.tags.reduce((accumulator, tag) => { | ||
return ArweaveUtils.concatBuffers([ | ||
accumulator, | ||
tag.get("name", { decode: true, string: false }), | ||
tag.get("value", { decode: true, string: false }), | ||
]); | ||
}, new Uint8Array()); | ||
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([ | ||
@@ -147,3 +145,3 @@ this.get("owner", { decode: true, string: false }), | ||
this.get("last_tx", { decode: true, string: false }), | ||
tags, | ||
ArweaveUtils.stringToBuffer(tagString) | ||
]); | ||
@@ -150,0 +148,0 @@ case 2: |
/// <reference types="node" /> | ||
import Api from "./lib/api"; | ||
import CryptoInterface, { SignatureOptions } from "./lib/crypto/crypto-interface"; | ||
import CryptoInterface from "./lib/crypto/crypto-interface"; | ||
import Transaction from "./lib/transaction"; | ||
@@ -32,3 +32,3 @@ import { JWKInterface } from "./lib/wallet"; | ||
}): Promise<string | Uint8Array>; | ||
sign(transaction: Transaction, jwk: JWKInterface, options?: SignatureOptions): Promise<void>; | ||
sign(transaction: Transaction, jwk: JWKInterface): Promise<void>; | ||
verify(transaction: Transaction): Promise<boolean>; | ||
@@ -35,0 +35,0 @@ post(transaction: Transaction | Buffer | string | object): Promise<{ |
@@ -140,5 +140,5 @@ "use strict"; | ||
} | ||
async sign(transaction, jwk, options) { | ||
async sign(transaction, jwk) { | ||
let dataToSign = await transaction.getSignatureData(); | ||
let rawSignature = await this.crypto.sign(jwk, dataToSign, options); | ||
let rawSignature = await this.crypto.sign(jwk, dataToSign); | ||
let id = await this.crypto.hash(rawSignature); | ||
@@ -145,0 +145,0 @@ transaction.setSignature({ |
{ | ||
"name": "arweave", | ||
"version": "1.10.1", | ||
"version": "1.10.2", | ||
"description": "Arweave JS client library", | ||
@@ -27,2 +27,3 @@ "main": "./node/index.js", | ||
"test:web": "npm run bundle:web && npx webpack --config-name web-tests && open test/web/web.html", | ||
"test:webwin": "npm run bundle:web && npx webpack --config-name web-tests && start test/web/web.html", | ||
"prettier:check": "prettier --check 'src/**/*.ts' 'test/**/*.ts'", | ||
@@ -29,0 +30,0 @@ "prettier:write": "prettier --write 'src/**/*.ts' 'test/**/*.ts'" |
import { JWKInterface } from "../wallet"; | ||
export interface SignatureOptions { | ||
saltLength?: number; | ||
} | ||
export default interface CryptoInterface { | ||
generateJWK(): Promise<JWKInterface>; | ||
sign(jwk: JWKInterface, data: Uint8Array, options?: SignatureOptions): Promise<Uint8Array>; | ||
sign(jwk: JWKInterface, data: Uint8Array): Promise<Uint8Array>; | ||
verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>; | ||
@@ -9,0 +6,0 @@ encrypt(data: Uint8Array, key: string | Uint8Array): Promise<Uint8Array>; |
/// <reference types="node" /> | ||
import { JWKInterface } from "../wallet"; | ||
import CryptoInterface, { SignatureOptions } from "./crypto-interface"; | ||
import CryptoInterface from "./crypto-interface"; | ||
export default class NodeCryptoDriver implements CryptoInterface { | ||
@@ -10,3 +10,3 @@ readonly keyLength = 4096; | ||
generateJWK(): Promise<JWKInterface>; | ||
sign(jwk: object, data: Uint8Array, { saltLength }?: SignatureOptions): Promise<Uint8Array>; | ||
sign(jwk: object, data: Uint8Array): Promise<Uint8Array>; | ||
verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>; | ||
@@ -13,0 +13,0 @@ hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>; |
@@ -34,3 +34,3 @@ "use strict"; | ||
} | ||
sign(jwk, data, { saltLength } = {}) { | ||
sign(jwk, data) { | ||
return new Promise((resolve, reject) => { | ||
@@ -43,3 +43,3 @@ resolve(crypto | ||
padding: constants.RSA_PKCS1_PSS_PADDING, | ||
saltLength, | ||
saltLength: 0 | ||
})); | ||
@@ -62,2 +62,3 @@ }); | ||
padding: constants.RSA_PKCS1_PSS_PADDING, | ||
saltLength: 0 | ||
}, signature)); | ||
@@ -64,0 +65,0 @@ }); |
/// <reference types="node" /> | ||
import { JWKInterface } from "../wallet"; | ||
import CryptoInterface, { SignatureOptions } from "./crypto-interface"; | ||
import CryptoInterface from "./crypto-interface"; | ||
export default class WebCryptoDriver implements CryptoInterface { | ||
@@ -11,3 +11,3 @@ readonly keyLength = 4096; | ||
generateJWK(): Promise<JWKInterface>; | ||
sign(jwk: JWKInterface, data: Uint8Array, { saltLength }?: SignatureOptions): Promise<Uint8Array>; | ||
sign(jwk: JWKInterface, data: Uint8Array): Promise<Uint8Array>; | ||
hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>; | ||
@@ -14,0 +14,0 @@ verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>; |
@@ -12,3 +12,3 @@ "use strict"; | ||
} | ||
this.driver = crypto.subtle; | ||
this.driver = window.crypto.subtle; | ||
} | ||
@@ -37,6 +37,6 @@ async generateJWK() { | ||
} | ||
async sign(jwk, data, { saltLength } = {}) { | ||
async sign(jwk, data) { | ||
let signature = await this.driver.sign({ | ||
name: "RSA-PSS", | ||
saltLength | ||
saltLength: 0 | ||
}, await this.jwkToCryptoKey(jwk), data); | ||
@@ -58,2 +58,3 @@ return new Uint8Array(signature); | ||
name: "RSA-PSS", | ||
saltLength: 0 | ||
}, key, signature, data); | ||
@@ -78,17 +79,22 @@ } | ||
detectWebCrypto() { | ||
if (typeof crypto === "undefined") { | ||
if (!window || !window.crypto || !window.crypto.subtle) { | ||
return false; | ||
} | ||
const subtle = crypto === null || crypto === void 0 ? void 0 : crypto.subtle; | ||
if (subtle === undefined) { | ||
let subtle = window.crypto.subtle; | ||
if (typeof subtle.generateKey != "function") { | ||
return false; | ||
} | ||
const names = [ | ||
"generateKey", | ||
"importKey", | ||
"exportKey", | ||
"digest", | ||
"sign", | ||
]; | ||
return names.every((name) => typeof subtle[name] === "function"); | ||
if (typeof subtle.importKey != "function") { | ||
return false; | ||
} | ||
if (typeof subtle.exportKey != "function") { | ||
return false; | ||
} | ||
if (typeof subtle.digest != "function") { | ||
return false; | ||
} | ||
if (typeof subtle.sign != "function") { | ||
return false; | ||
} | ||
return true; | ||
} | ||
@@ -95,0 +101,0 @@ async encrypt(data, key) { |
@@ -132,9 +132,7 @@ "use strict"; | ||
case 1: | ||
let tags = this.tags.reduce((accumulator, tag) => { | ||
return ArweaveUtils.concatBuffers([ | ||
accumulator, | ||
tag.get("name", { decode: true, string: false }), | ||
tag.get("value", { decode: true, string: false }), | ||
]); | ||
}, new Uint8Array()); | ||
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([ | ||
@@ -147,3 +145,3 @@ this.get("owner", { decode: true, string: false }), | ||
this.get("last_tx", { decode: true, string: false }), | ||
tags, | ||
ArweaveUtils.stringToBuffer(tagString) | ||
]); | ||
@@ -150,0 +148,0 @@ case 2: |
/// <reference types="node" /> | ||
import Api from "./lib/api"; | ||
import CryptoInterface, { SignatureOptions } from "./lib/crypto/crypto-interface"; | ||
import CryptoInterface from "./lib/crypto/crypto-interface"; | ||
import Transaction from "./lib/transaction"; | ||
@@ -32,3 +32,3 @@ import { JWKInterface } from "./lib/wallet"; | ||
}): Promise<string | Uint8Array>; | ||
sign(transaction: Transaction, jwk: JWKInterface, options?: SignatureOptions): Promise<void>; | ||
sign(transaction: Transaction, jwk: JWKInterface): Promise<void>; | ||
verify(transaction: Transaction): Promise<boolean>; | ||
@@ -35,0 +35,0 @@ post(transaction: Transaction | Buffer | string | object): Promise<{ |
@@ -140,5 +140,5 @@ "use strict"; | ||
} | ||
async sign(transaction, jwk, options) { | ||
async sign(transaction, jwk) { | ||
let dataToSign = await transaction.getSignatureData(); | ||
let rawSignature = await this.crypto.sign(jwk, dataToSign, options); | ||
let rawSignature = await this.crypto.sign(jwk, dataToSign); | ||
let id = await this.crypto.hash(rawSignature); | ||
@@ -145,0 +145,0 @@ transaction.setSignature({ |
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1257837
14047
0