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

feat!: chain Asset Lock proof #296

Merged
merged 34 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/StateRepositoryInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,36 @@
* @async
* @method
* @name StateRepository#verifyInstantLock
* @param {InstantLock} instantLock
* @returns {Promise<boolean>}
*/

/**
* Check if AssetLock Transaction outPoint exists in spent list
* Store AssetLock Transaction outPoint in spent list
*
* @async
* @method
* @name StateRepository#checkAssetLockTransactionOutPointExists
* @name StateRepository#storeAssetLockTransactionOutPoint
* @param {Buffer} outPointBuffer
* @returns {Promise<boolean>}
* @returns {Promise<void>}
*/

/**
* Store AssetLock Transaction outPoint in spent list
* Verify AssetLock outPoint
*
* @async
* @method
* @name StateRepository#storeAssetLockTransactionOutPoint
* @name StateRepository#checkAssetLockTransactionOutPointAlreadyUsed
* @param {Buffer} outPointBuffer
* @returns {Promise<void>}
* @returns {Promise<boolean>}
*/

/**
* Verify AssetLock height
*
* @async
* @method
* @name StateRepository#verifyChainLockHeight
* @param {number} height
* @returns {Promise<boolean>}
*/
23 changes: 23 additions & 0 deletions lib/errors/InvalidIdentityAssetLockProofHeightError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const ConsensusError = require('./ConsensusError');

class InvalidIdentityAssetLockProofHeightError extends ConsensusError {
/**
*
* @param {number} height
*/
constructor(height) {
super('Asset lock proof height is greater than consensus height');

this.height = height;
}

/**
*
* @returns {number}
*/
getHeight() {
return this.height;
}
}

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

class InvalidIdentityAssetLockProofOutPointError 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 = InvalidIdentityAssetLockProofOutPointError;
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} 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}
*/
getAssetLock() {
return this.assetLock;
getAssetLockProof() {
return this.assetLockProof;
}

/**
Expand Down
18 changes: 6 additions & 12 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 {PublicKey[]} publicKeys
* @return {Identity}
*/
create(assetLockTransaction, outputIndex, assetLockProof, publicKeys) {
create(assetLockProof, publicKeys) {
return this.factory.create(
assetLockTransaction,
outputIndex,
assetLockProof,
publicKeys,
);
Expand Down Expand Up @@ -86,10 +82,12 @@ class IdentityFacade {
* Create Asset Lock with proofs
*
* @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);
}

/**
Expand All @@ -106,16 +104,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
* @return {IdentityTopUpTransition}
*/
createIdentityTopUpTransition(identityId, assetLockTransaction, outputIndex, assetLockProof) {
createIdentityTopUpTransition(identityId, assetLockProof) {
return this.factory.createIdentityTopUpTransition(
identityId,
assetLockTransaction,
outputIndex,
assetLockProof,
);
}
Expand Down
35 changes: 11 additions & 24 deletions lib/identity/IdentityFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const IdentityTopUpTransition = require('./stateTransitions/identityTopUpTransit

const InvalidIdentityError = require('./errors/InvalidIdentityError');
const SerializedObjectParsingError = require('../errors/SerializedObjectParsingError');
const AssetLock = require('./stateTransitions/assetLock/AssetLock');
const InstantAssetLockProof = require('./stateTransitions/assetLock/proof/instant/InstantAssetLockProof');

class IdentityFactory {
Expand All @@ -22,22 +21,14 @@ class IdentityFactory {
/**
* Create Identity
*
* @param {Transaction} assetLockTransaction
* @param {number} outputIndex
* @param {InstantAssetLockProof} assetLockProof
* @param {PublicKey[]} publicKeys
* @return {Identity}
*/
create(assetLockTransaction, outputIndex, assetLockProof, publicKeys) {
const assetLock = new AssetLock({
transaction: assetLockTransaction.toBuffer(),
outputIndex,
proof: assetLockProof.toObject(),
});

create(assetLockProof, publicKeys) {
const identity = new Identity({
protocolVersion: Identity.PROTOCOL_VERSION,
id: assetLock.createIdentifier(),
id: assetLockProof.createIdentifier(),
balance: 0,
publicKeys: publicKeys.map((publicKey, i) => ({
id: i,
Expand All @@ -47,7 +38,7 @@ class IdentityFactory {
revision: 0,
});

identity.setAssetLock(assetLock);
identity.setAssetLockProof(assetLockProof);

return identity;
}
Expand Down Expand Up @@ -102,11 +93,15 @@ class IdentityFactory {
* Create Asset Lock with proofs
*
* @param {InstantLock} instantLock
* @param {Transaction} assetLockTransaction
* @param {number} outputIndex
* @returns {InstantAssetLockProof}
*/
createInstantAssetLockProof(instantLock) {
createInstantAssetLockProof(instantLock, assetLockTransaction, outputIndex) {
return new InstantAssetLockProof({
instantLock: instantLock.toBuffer(),
transaction: assetLockTransaction.toBuffer(),
outputIndex,
});
}

Expand All @@ -119,7 +114,7 @@ class IdentityFactory {
createIdentityCreateTransition(identity) {
const stateTransition = new IdentityCreateTransition({
protocolVersion: Identity.PROTOCOL_VERSION,
assetLock: identity.getAssetLock().toObject(),
assetLockProof: identity.getAssetLockProof().toObject(),
});

stateTransition.setPublicKeys(identity.getPublicKeys());
Expand All @@ -131,22 +126,14 @@ class IdentityFactory {
* Create identity top up transition
*
* @param {Identifier|Buffer|string} identityId - identity to top up
* @param {Transaction} assetLockTransaction
* @param {number} outputIndex
* @param {InstantAssetLockProof} assetLockProof
* @return {IdentityTopUpTransition}
*/
createIdentityTopUpTransition(identityId, assetLockTransaction, outputIndex, assetLockProof) {
const assetLock = new AssetLock({
transaction: assetLockTransaction.toBuffer(),
outputIndex,
proof: assetLockProof.toObject(),
});

createIdentityTopUpTransition(identityId, assetLockProof) {
return new IdentityTopUpTransition({
protocolVersion: Identity.PROTOCOL_VERSION,
identityId,
assetLock: assetLock.toObject(),
assetLockProof: assetLockProof.toObject(),
});
}
}
Expand Down
117 changes: 0 additions & 117 deletions lib/identity/stateTransitions/assetLock/AssetLock.js

This file was deleted.

Loading