Skip to content

Commit

Permalink
feat: 🎸 add a sign method to append signed proofs (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamJLemmon authored May 4, 2020
1 parent b5f8242 commit 4fbc2c2
Show file tree
Hide file tree
Showing 10 changed files with 649 additions and 428 deletions.
113 changes: 111 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"dependencies": {
"ajv": "6.10.2",
"debug": "^4.1.1",
"ethers": "^4.0.47",
"flatley": "^5.2.0",
"js-sha3": "^0.8.0",
"lodash": "^4.17.15",
Expand Down
23 changes: 23 additions & 0 deletions src/@types/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export interface Signature {
merkleRoot: string;
}

export interface ProofSigningOptions {
privateKey: string;
verificationMethod: string;
type: ProofType;
proofPurpose?: ProofPurpose;
}

export interface ObfuscationMetadata {
obfuscatedData?: string[];
}
Expand All @@ -30,6 +37,22 @@ export interface WrappedDocument<T = any> {
schema?: string;
privacy?: ObfuscationMetadata;
}
export enum ProofType {
EcdsaSecp256k1Signature2019 = "EcdsaSecp256k1Signature2019"
}
export enum ProofPurpose {
AssertionMethod = "assertionMethod"
}
export interface Proof {
type: ProofType;
created: string;
proofPurpose: ProofPurpose;
verificationMethod: string;
signature: string;
}
export interface SignedWrappedDocument<T = any> extends WrappedDocument<T> {
proof: Proof;
}

// feel free to improve, as long as this project compile without changes :)
// once salted, every property is turned into a string
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const validateSchema = (document: WrappedDocument): boolean => {

export { digestDocument } from "./digest";
export { obfuscateDocument } from "./privacy";
export { sign } from "./sign";
export { checkProof, MerkleTree, wrap, verify as verifySignature } from "./signature";
export { utils, isSchemaValidationError };
export * from "./@types/document";
Expand Down
102 changes: 51 additions & 51 deletions src/schema/2.0/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,34 @@
"required": ["type", "location"],
"additionalProperties": false
},
"documentStore": {
"issuer": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Issuer's name"
},
"documentStore": {
"type": "string",
"pattern": "^0x[a-fA-F0-9]{40}$",
"description": "Smart contract address of document store"
},
"identityProof": { "$ref": "#/definitions/identityProof" }
},
"required": ["name", "documentStore", "identityProof"],
"not": {
"anyOf": [
{
"required": ["certificateStore"]
},
{
"required": ["tokenRegistry"]
}
]
},
"required": ["name", "identityProof"],
"additionalProperties": true
},
"documentStore": {
"allOf": [
{ "$ref": "#/definitions/issuer" },
{
"type": "object",
"properties": {
"documentStore": {
"type": "string",
"pattern": "^0x[a-fA-F0-9]{40}$",
"description": "Smart contract address of document store"
}
},
"required": ["documentStore"]
}
]
},
"certificateStore": {
"type": "object",
"properties": {
Expand All @@ -60,44 +61,23 @@
}
},
"required": ["name", "certificateStore"],
"not": {
"anyOf": [
{
"required": ["documentStore"]
},
{
"required": ["tokenRegistry"]
}
]
},
"additionalProperties": true
},
"tokenRegistry": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Issuer's name"
},
"tokenRegistry": {
"type": "string",
"pattern": "^0x[a-fA-F0-9]{40}$",
"description": "Smart contract address of token registry"
},
"identityProof": { "$ref": "#/definitions/identityProof" }
},
"required": ["name", "tokenRegistry", "identityProof"],
"not": {
"anyOf": [
{
"required": ["documentStore"]
"allOf": [
{ "$ref": "#/definitions/issuer" },
{
"type": "object",
"properties": {
"tokenRegistry": {
"type": "string",
"pattern": "^0x[a-fA-F0-9]{40}$",
"description": "Smart contract address of token registry"
}
},
{
"required": ["certificateStore"]
}
]
},
"additionalProperties": true
"required": ["tokenRegistry"]
}
]
}
},
"type": "object",
Expand Down Expand Up @@ -150,6 +130,26 @@
},
{
"$ref": "#/definitions/certificateStore"
},
{
"allOf": [
{ "$ref": "#/definitions/issuer" },
{
"not": {
"anyOf": [
{
"required": ["certificateStore"]
},
{
"required": ["tokenRegistry"]
},
{
"required": ["documentStore"]
}
]
}
}
]
}
]
},
Expand Down
Loading

0 comments on commit 4fbc2c2

Please sign in to comment.