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

change PublicKey labels

This commit is contained in:
Bill Barman 2018-11-21 08:55:02 +08:00
parent 610bab81af
commit d67ed4bc15
3 changed files with 24 additions and 25 deletions

View File

@ -139,9 +139,9 @@ export default class DDO {
public addSignature(keyType?: string): string {
if ( keyType == null ) {
keyType = PublicKey.PEM
keyType = PublicKey.STORE_AS_PEM
}
if (keyType === PublicKey.PEM ) {
if (keyType === PublicKey.STORE_AS_PEM ) {
// generate the key pairs
const keys = ursa.generatePrivateKey(1024, 65537)

View File

@ -1,6 +1,4 @@
import * as Web3 from "web3"
interface IPublicKey {
id?: string
owner?: string
@ -10,11 +8,11 @@ interface IPublicKey {
export default class PublicKey {
public static TYPE_RSA: string = "RsaSignatureAuthentication2018"
public static PEM: string = "publicKeyPem"
public static JWK: string = "publicKeyJwk"
public static HEX: string = "publicKeyHex"
public static BASE64: string = "publicKeyBase64"
public static BASE85: string = "publicKeyBase85"
public static STORE_AS_PEM: string = "publicKeyPem"
public static STORE_AS_JWK: string = "publicKeyJwk"
public static STORE_AS_HEX: string = "publicKeyHex"
public static STORE_AS_BASE64: string = "publicKeyBase64"
public static STORE_AS_BASE85: string = "publicKeyBase85"
public id: string
public owner: string
@ -25,7 +23,7 @@ export default class PublicKey {
this.id = data.id
this.owner = data.owner
this.type = data.type
this.value = data[PublicKey.PEM]
this.value = data[PublicKey.STORE_AS_PEM]
}
public toData(): IPublicKey {
@ -33,7 +31,7 @@ export default class PublicKey {
id: this.id,
owner: this.owner,
type: this.type,
[PublicKey.PEM]: this.value,
[PublicKey.STORE_AS_PEM]: this.value,
} as IPublicKey
}
@ -48,22 +46,23 @@ export default class PublicKey {
let value = this.value
let buffer = null
switch (this.type) {
case PublicKey.PEM:
case PublicKey.STORE_AS_PEM:
value = this.value
break
case PublicKey.JWK:
case PublicKey.STORE_AS_JWK:
// TODO: implement
break
case PublicKey.HEX:
value = Web3.utils.hexToAscii(this.value)
case PublicKey.STORE_AS_HEX:
buffer = Buffer.from(this.value, "hex")
value = buffer.toString("binary")
break
case PublicKey.BASE64:
buffer = new Buffer(this.value, "base64")
value = buffer.toString("ascii")
case PublicKey.STORE_AS_BASE64:
buffer = Buffer.from(this.value, "base64")
value = buffer.toString("binary")
break
case PublicKey.BASE85:
buffer = new Buffer(this.value, "base85")
value = buffer.toString("ascii")
case PublicKey.STORE_AS_BASE85:
buffer = Buffer.from(this.value, "base85")
value = buffer.toString("binary")
break
}
return value

View File

@ -88,11 +88,11 @@ describe("libDDO", () => {
assert(ddo)
assert(ddo.validate())
const service = ddo.getService("Metadata")
assert(service)
const serviceFound = ddo.getService("Metadata")
assert(serviceFound)
const service = ddo.getService("MetadataCannotFind")
assert(service == null)
const serviceNotFound = ddo.getService("MetadataCannotFind")
assert(serviceNotFound == null)
// var item = ddo.findServiceKeyValue("serviceDefinitionId", "test")
})