1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

better default parameter parsing

This commit is contained in:
Bill Barman 2018-11-22 23:30:07 +08:00
parent cb7b8d51f1
commit 783f653119
3 changed files with 16 additions and 22 deletions

16
package-lock.json generated
View File

@ -157,7 +157,7 @@
}, },
"@types/events": { "@types/events": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "http://registry.npmjs.org/@types/events/-/events-1.2.0.tgz", "resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
"integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA==", "integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA==",
"dev": true "dev": true
}, },
@ -1435,7 +1435,7 @@
"dependencies": { "dependencies": {
"pify": { "pify": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw="
} }
} }
@ -1500,7 +1500,7 @@
"dependencies": { "dependencies": {
"file-type": { "file-type": {
"version": "3.9.0", "version": "3.9.0",
"resolved": "http://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", "resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz",
"integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek=" "integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek="
}, },
"get-stream": { "get-stream": {
@ -1514,7 +1514,7 @@
}, },
"pify": { "pify": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw="
} }
} }
@ -3764,7 +3764,7 @@
}, },
"media-typer": { "media-typer": {
"version": "0.3.0", "version": "0.3.0",
"resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
}, },
"mem": { "mem": {
@ -5519,7 +5519,7 @@
}, },
"path-is-absolute": { "path-is-absolute": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
}, },
"path-key": { "path-key": {
@ -6523,7 +6523,7 @@
}, },
"tar": { "tar": {
"version": "2.2.1", "version": "2.2.1",
"resolved": "http://registry.npmjs.org/tar/-/tar-2.2.1.tgz", "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz",
"integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=", "integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=",
"requires": { "requires": {
"block-stream": "0.0.9", "block-stream": "0.0.9",
@ -7101,7 +7101,7 @@
}, },
"utf8": { "utf8": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "http://registry.npmjs.org/utf8/-/utf8-2.1.1.tgz", "resolved": "https://registry.npmjs.org/utf8/-/utf8-2.1.1.tgz",
"integrity": "sha1-LgHbAvfY0JRPdxBPFgnrDDBM92g=" "integrity": "sha1-LgHbAvfY0JRPdxBPFgnrDDBM92g="
}, },
"util": { "util": {

View File

@ -96,7 +96,6 @@ export default class DDO {
if (typeof did === "object") { if (typeof did === "object") {
this.readFromData(did) this.readFromData(did)
} }
} }
/* /*
@ -195,10 +194,8 @@ export default class DDO {
* *
*/ */
public addSignature(encoding?: string, isEmbedded?: boolean): string { public addSignature(encoding?: string, isEmbedded?: boolean): string {
if ( encoding == null ) { encoding = encoding ? encoding : DDO.ENCODING_TYPES.PEM
encoding = DDO.ENCODING_TYPES.PEM isEmbedded = isEmbedded ? isEmbedded : false
}
isEmbedded = isEmbedded == null ? false : isEmbedded
encoding = encoding.toLowerCase() encoding = encoding.toLowerCase()
// generate the key pairs // generate the key pairs
@ -262,10 +259,8 @@ export default class DDO {
* hash text * hash text
* *
*/ */
public addProof(authIndex, privateKey, signatureText?) { public addProof(privateKey: string, authIndex?: number, signatureText?: string) {
if ( authIndex == null ) { authIndex = authIndex ? authIndex : 0
authIndex = 0
}
const authentication = this.authentications[authIndex] const authentication = this.authentications[authIndex]
let publicKey = null let publicKey = null
@ -531,9 +526,8 @@ export default class DDO {
* *
*/ */
public validateProof(signatureText?: string): boolean { public validateProof(signatureText?: string): boolean {
if ( signatureText == null ) { signatureText = signatureText ? signatureText : this.hashTextList().join()
signatureText = this.hashTextList().join()
}
if ( !this.isProofDefined() ) { if ( !this.isProofDefined() ) {
return false return false
} }

View File

@ -141,7 +141,7 @@ describe("libDDO", () => {
assert(ddo) assert(ddo)
const privateKey = ddo.addSignature() const privateKey = ddo.addSignature()
assert(privateKey.match("-----BEGIN RSA PRIVATE KEY-----")) assert(privateKey.match("-----BEGIN RSA PRIVATE KEY-----"))
ddo.addProof(0, privateKey) ddo.addProof(privateKey)
// console.log(ddo.toJSON()) // console.log(ddo.toJSON())
assert(ddo.validateProof()) assert(ddo.validateProof())
}) })
@ -152,7 +152,7 @@ describe("libDDO", () => {
assert(ddo) assert(ddo)
const privateKey = ddo.addSignature("pem", true) const privateKey = ddo.addSignature("pem", true)
assert(privateKey.match("-----BEGIN RSA PRIVATE KEY-----")) assert(privateKey.match("-----BEGIN RSA PRIVATE KEY-----"))
ddo.addProof(0, privateKey) ddo.addProof(privateKey)
// console.log(ddo.toJSON()) // console.log(ddo.toJSON())
assert(ddo.validateProof()) assert(ddo.validateProof())
}) })