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 { public addSignature(keyType?: string): string {
if ( keyType == null ) { 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 // generate the key pairs
const keys = ursa.generatePrivateKey(1024, 65537) const keys = ursa.generatePrivateKey(1024, 65537)

View File

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

View File

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