1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
This commit is contained in:
Bill Barman 2018-11-20 17:17:53 +08:00
parent cd7cd1e337
commit 99f215300e
3 changed files with 34 additions and 36 deletions

View File

@ -4,10 +4,9 @@ import Proof from "./Proof"
import PublicKey from "./PublicKey" import PublicKey from "./PublicKey"
import Service from "./Service" import Service from "./Service"
import * as ursa from "ursa"
import * as Web3 from "web3" import * as Web3 from "web3"
const ursa = require('ursa');
interface IDDO { interface IDDO {
id: string id: string
created?: string created?: string
@ -20,6 +19,8 @@ interface IDDO {
export default class DDO { export default class DDO {
public static CONTEXT: string = "https://w3id.org/future-method/v1"
public static validateSignature(text: string, keyValue: string, signature: string, authenticationType: string) { public static validateSignature(text: string, keyValue: string, signature: string, authenticationType: string) {
if ( authenticationType === Authentication.TYPE_RSA ) { if ( authenticationType === Authentication.TYPE_RSA ) {
// var key = ursa.createPublicKey(keyValue, "utf8") // var key = ursa.createPublicKey(keyValue, "utf8")
@ -44,7 +45,6 @@ export default class DDO {
return false return false
} }
public static CONTEXT: string = "https://w3id.org/future-method/v1"
public context: string = DDO.CONTEXT public context: string = DDO.CONTEXT
public did: string public did: string
public created: string public created: string
@ -151,21 +151,19 @@ export default class DDO {
keyType = PublicKey.PEM keyType = PublicKey.PEM
} }
if (keyType === PublicKey.PEM ) { if (keyType === PublicKey.PEM ) {
var keys = ursa.generatePrivateKey(1024, 65537) const keys = ursa.generatePrivateKey(1024, 65537)
const nextIndex = this.publicKeys.length + 1 const nextIndex = this.publicKeys.length + 1
const keyId = (this.did ? this.did : '' ) + "#keys=" + nextIndex const keyId = (this.did ? this.did : "" ) + "#keys=" + nextIndex
var publicKey = new PublicKey({id: keyId, owner: keyId, type: keyType}) const publicKey = new PublicKey({id: keyId, owner: keyId, type: keyType})
publicKey.value = keys.toPublicPem("utf8") publicKey.value = keys.toPublicPem("utf8")
this.publicKeys.push(publicKey) this.publicKeys.push(publicKey)
return keys.toPrivatePem("utf8") return keys.toPrivatePem("utf8")
} }
return null return null
} }
public addService(data): Service { public addService(data): Service {
var service = new Service(data) const service = new Service(data)
if (service.id == null ) { if (service.id == null ) {
service.id = this.did service.id = this.did
} }

View File

@ -45,26 +45,26 @@ export default class PublicKey {
} }
public decodeValue(): string { public decodeValue(): string {
var value = this.value let value = this.value
var buffer let buffer = null
switch(this.type) { switch (this.type) {
case PublicKey.PEM: case PublicKey.PEM:
value = this.value value = this.value
break; break
case PublicKey.JWK: case PublicKey.JWK:
// TODO: implement // TODO: implement
break; break
case PublicKey.HEX: case PublicKey.HEX:
value = Web3.utils.hexToAscii(this.value) value = Web3.utils.hexToAscii(this.value)
break; break
case PublicKey.BASE64: case PublicKey.BASE64:
buffer = new Buffer(this.value, 'base64') buffer = new Buffer(this.value, "base64")
value = buffer.toString('ascii') value = buffer.toString("ascii")
break; break
case PublicKey.BASE85: case PublicKey.BASE85:
buffer = new Buffer(this.value, 'base85') buffer = new Buffer(this.value, "base85")
value = buffer.toString('ascii') value = buffer.toString("ascii")
break; break
} }
return value return value
} }