Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
feat!: ChainLock Asset Lock proof (#296)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Shumkov <ivan@shumkov.ru>
  • Loading branch information
Konstantin Shuplenkov and shumkov authored Apr 27, 2021
1 parent 754d85f commit 633876f
Show file tree
Hide file tree
Showing 54 changed files with 2,166 additions and 1,111 deletions.
5 changes: 3 additions & 2 deletions lib/StateRepositoryInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
* @async
* @method
* @name StateRepository#verifyInstantLock
* @param {InstantLock} instantLock
* @returns {Promise<boolean>}
*/

Expand All @@ -134,7 +135,7 @@
*
* @async
* @method
* @name StateRepository#checkAssetLockTransactionOutPointExists
* @name StateRepository#isAssetLockTransactionOutPointAlreadyUsed
* @param {Buffer} outPointBuffer
* @returns {Promise<boolean>}
*/
Expand All @@ -144,7 +145,7 @@
*
* @async
* @method
* @name StateRepository#storeAssetLockTransactionOutPoint
* @name StateRepository#markAssetLockTransactionOutPointAsUsed
* @param {Buffer} outPointBuffer
* @returns {Promise<void>}
*/
23 changes: 23 additions & 0 deletions lib/errors/IdentityAssetLockProofOutPointIsAlreadyUsedError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const ConsensusError = require('./ConsensusError');

class IdentityAssetLockProofOutPointIsAlreadyUsedError extends ConsensusError {
/**
*
* @param {Buffer} outPoint
*/
constructor(outPoint) {
super('Asset lock proof outPoint was already used');

this.outPoint = outPoint;
}

/**
*
* @returns {Buffer}
*/
getOutPoint() {
return this.outPoint;
}
}

module.exports = IdentityAssetLockProofOutPointIsAlreadyUsedError;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const ConsensusError = require('./ConsensusError');

class IdentityAssetLockProofTransactionOutPointIsAlreadyUsedError extends ConsensusError {
/**
*
* @param {Buffer} outPoint
*/
constructor(outPoint) {
super('Asset lock proof transaction outPoint was already used');

this.outPoint = outPoint;
}

/**
*
* @returns {Buffer}
*/
getOutPoint() {
return this.outPoint;
}
}

module.exports = IdentityAssetLockProofTransactionOutPointIsAlreadyUsedError;
23 changes: 23 additions & 0 deletions lib/errors/IdentityAssetLockTransactionIsNotFoundError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const ConsensusError = require('./ConsensusError');

class IdentityAssetLockTransactionIsNotFoundError extends ConsensusError {
/**
*
* @param {Buffer} outPoint
*/
constructor(outPoint) {
super('Asset Lock transaction with specified outPoint was not found');

this.outPoint = outPoint;
}

/**
*
* @returns {Buffer}
*/
getOutPoint() {
return this.outPoint;
}
}

module.exports = IdentityAssetLockTransactionIsNotFoundError;
33 changes: 33 additions & 0 deletions lib/errors/InvalidAssetLockProofCoreChainHeightError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const ConsensusError = require('./ConsensusError');

class InvalidIdentityAssetLockProofCoreHeightError extends ConsensusError {
/**
*
* @param {number} proofCoreChainLockedHeight
* @param {number} currentCoreChainLockedHeight
*/
constructor(proofCoreChainLockedHeight, currentCoreChainLockedHeight) {
super(`Asset Lock proof core chain height ${proofCoreChainLockedHeight} is higher than the current consensus core height ${currentCoreChainLockedHeight}.`);

this.proofCoreChainLockedHeight = proofCoreChainLockedHeight;
this.currentCoreChainLockedHeight = currentCoreChainLockedHeight;
}

/**
*
* @returns {number}
*/
getProofCoreChainLockedHeight() {
return this.proofCoreChainLockedHeight;
}

/**
*
* @returns {number}
*/
getCurrentCoreChainLockedHeight() {
return this.currentCoreChainLockedHeight;
}
}

module.exports = InvalidIdentityAssetLockProofCoreHeightError;
33 changes: 33 additions & 0 deletions lib/errors/InvalidAssetLockProofTransactionHeightError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const ConsensusError = require('./ConsensusError');

class InvalidAssetLockProofTransactionHeightError extends ConsensusError {
/**
*
* @param {number} proofCoreChainLockedHeight
* @param {number} transactionHeight
*/
constructor(proofCoreChainLockedHeight, transactionHeight) {
super(`Core chain locked height ${proofCoreChainLockedHeight} must be higher than block ${transactionHeight || ''} with Asset Lock transaction`);

this.proofCoreChainLockedHeight = proofCoreChainLockedHeight;
this.transactionHeight = transactionHeight;
}

/**
*
* @returns {number}
*/
getProofCoreChainLockedHeight() {
return this.proofCoreChainLockedHeight;
}

/**
*
* @returns {number}
*/
getTransactionHeight() {
return this.transactionHeight;
}
}

module.exports = InvalidAssetLockProofTransactionHeightError;
33 changes: 33 additions & 0 deletions lib/errors/InvalidIdentityAssetLockProofCoreHeightError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const ConsensusError = require('./ConsensusError');

class InvalidIdentityAssetLockProofCoreHeightError extends ConsensusError {
/**
*
* @param {number} proofCoreChainLockedHeight
* @param {number} currentCoreChainLockedHeight
*/
constructor(proofCoreChainLockedHeight, currentCoreChainLockedHeight) {
super(`Asset Lock proof core height ${proofCoreChainLockedHeight} is greater than current consensus core height ${currentCoreChainLockedHeight}.`);

this.proofCoreChainLockedHeight = proofCoreChainLockedHeight;
this.currentCoreChainLockedHeight = currentCoreChainLockedHeight;
}

/**
*
* @returns {number}
*/
getProofCoreChainLockedHeight() {
return this.proofCoreChainLockedHeight;
}

/**
*
* @returns {number}
*/
getCurrentCoreChainLockedHeight() {
return this.currentCoreChainLockedHeight;
}
}

module.exports = InvalidIdentityAssetLockProofCoreHeightError;
23 changes: 23 additions & 0 deletions lib/errors/UnknownAssetLockProofError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const ConsensusError = require('./ConsensusError');

class UnknownAssetLockProofError extends ConsensusError {
/**
*
* @param {number} type
*/
constructor(type) {
super('Unknown Asset lock proof type');

this.type = type;
}

/**
*
* @returns {number}
*/
getType() {
return this.type;
}
}

module.exports = UnknownAssetLockProofError;
16 changes: 8 additions & 8 deletions lib/identity/Identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,24 @@ class Identity {
}

/**
* Set asset lock
* Set asset lock proof
*
* @param {AssetLock} assetLock
* @param {InstantAssetLockProof|ChainAssetLockProof} assetLockProof
* @return {Identity}
*/
setAssetLock(assetLock) {
this.assetLock = assetLock;
setAssetLockProof(assetLockProof) {
this.assetLockProof = assetLockProof;

return this;
}

/**
* Get locked out point
* Get asset lock proof
*
* @return {AssetLock}
* @return {InstantAssetLockProof|ChainAssetLockProof}
*/
getAssetLock() {
return this.assetLock;
getAssetLockProof() {
return this.assetLockProof;
}

/**
Expand Down
35 changes: 20 additions & 15 deletions lib/identity/IdentityFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ class IdentityFacade {
/**
* Create Identity
*
* @param {Transaction} assetLockTransaction
* @param {number} outputIndex
* @param {InstantAssetLockProof} assetLockProof
* @param {InstantAssetLockProof|ChainAssetLockProof} assetLockProof
* @param {PublicKey[]} publicKeys
* @return {Identity}
*/
create(assetLockTransaction, outputIndex, assetLockProof, publicKeys) {
create(assetLockProof, publicKeys) {
return this.factory.create(
assetLockTransaction,
outputIndex,
assetLockProof,
publicKeys,
);
Expand Down Expand Up @@ -83,13 +79,26 @@ class IdentityFacade {
}

/**
* Create Asset Lock with proofs
* Create Instant Asset Lock proof
*
* @param {InstantLock} instantLock
* @param {Transaction} assetLockTransaction
* @param {number} outputIndex
* @returns {InstantAssetLockProof}
*/
createInstantAssetLockProof(instantLock) {
return this.factory.createInstantAssetLockProof(instantLock);
createInstantAssetLockProof(instantLock, assetLockTransaction, outputIndex) {
return this.factory.createInstantAssetLockProof(instantLock, assetLockTransaction, outputIndex);
}

/**
* Create Chain Asset Lock proof
*
* @param {number} coreChainLockedHeight
* @param {Buffer} outPoint
* @returns {InstantAssetLockProof|ChainAssetLockProof}
*/
createChainAssetLockProof(coreChainLockedHeight, outPoint) {
return this.factory.createChainAssetLockProof(coreChainLockedHeight, outPoint);
}

/**
Expand All @@ -106,16 +115,12 @@ class IdentityFacade {
* Create identity top up transition
*
* @param {Identifier|Buffer|string} identityId - identity to top up
* @param {Transaction} assetLockTransaction
* @param {number} outputIndex
* @param {InstantAssetLockProof} assetLockProof
* @param {InstantAssetLockProof|ChainAssetLockProof} assetLockProof
* @return {IdentityTopUpTransition}
*/
createIdentityTopUpTransition(identityId, assetLockTransaction, outputIndex, assetLockProof) {
createIdentityTopUpTransition(identityId, assetLockProof) {
return this.factory.createIdentityTopUpTransition(
identityId,
assetLockTransaction,
outputIndex,
assetLockProof,
);
}
Expand Down
Loading

0 comments on commit 633876f

Please sign in to comment.