Giter Site home page Giter Site logo

Comments (7)

 avatar commented on May 27, 2024 2

The off-chain process to create an Aggregate Complete Transaction has a strong dependency on the technologies used each project, but we could create a recommendation guide as @dgarcia360 shared.

@gimyboya , the solution that you have shared is great to start working with ACT, thank you for taking your time to code it and share it here! 😃

The idea would be the following:

  • Initiator sign the aggregate transaction.
  • The initiator sends offline (could be through their server) the aggregate transaction to each participant.
  • Each participant signs individually.
  • Initiator creates a new SignedTransaction composing all the cosignatures and announces it.

Adding some diagrams for a better explanation.

act off chain signing

Because it happens off-chain, we assume the there is a database to store ACT (recovery reasons) and a queue or an internal REST endpoint to pass the ACT between systems.

Each phase has its own business logic, we should help in the flow and common tasks that happen in each phase.

communication between systems

We need to serialize the ACT (and transactions in general) to be stored in the database and sent via RESTful API. nem2-sdk have to provide a method to serialize the ACT as JSON at least. As it is today is possible since developers could do it manually, but we have to provide a class method to ensure multiple system compatibility, we assumed it happens in the same system, but it may not.

state verification

The phase#2 just requires one of those to sign the transaction, the case study does not require to check if the ACT is complete or not because of Multisig configuration, but other systems may need to check if the required cosignatures are in ACT or not before announcing the transaction.

ℹī¸ An Aggregate Complete Transaction has to know if he has all the required cosignatures, up to date, it's developer responsibility to know and check the cosignatures in a manual way. We should create a method in the nem2-sdk that given an ACT, check if it has all the required cosigners automatically.

current problems

nem2-sdk doesn't allow a easy way to recreate an ACT.

summary of required

  • Serialization
  • Check ACT status with chain information
  • Create an easier way to re-create the ACT.

ℹī¸ Still unmatured reasoning but a good place to start.

from symbol-docs.

khawarizmus avatar khawarizmus commented on May 27, 2024 1

not sure if my code is correct but let's give it a try

import {
  PublicAccount,
  NetworkType,
  TransferTransaction,
  Deadline,
  PlainMessage,
  Address,
  AggregateTransaction,
  XEM,
  Account} from 'nem2-sdk';

const initiatorPrivateKey = process.env.COSIGNATORY_1_PRIVATE_KEY as string;

const cosignatoriesPks: string[] = [
  'pk1',
  'pk2',
  'pk3',
];
const recipientAddress = 'SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54';

const multisigAccountPublicKey = '202B3861F34F6141E120742A64BC787D6EBC59C9EFB996F4856AA9CBEE11CD31';
const multisigAccount = PublicAccount.createFromPublicKey(multisigAccountPublicKey, NetworkType.MIJIN_TEST);
const initiator = Account.createFromPrivateKey(initiatorPrivateKey, NetworkType.MIJIN_TEST);
// array of cosignatories account
const cosignatories: Account[] = [];

cosignatoriesPks.forEach((pk) => {
  // populate the array of cosignatories by using the array of private kyies
  cosignatories.push(Account.createFromPrivateKey(pk, NetworkType.MIJIN_TEST));
});

const transferTransaction = TransferTransaction.create(
  Deadline.create(),
  Address.createFromRawAddress(recipientAddress),
  [XEM.createRelative(10)],
  PlainMessage.create('sending 10 nem:xem'),
  NetworkType.MIJIN_TEST,
);

const aggregateTransaction = AggregateTransaction.createComplete(
  Deadline.create(),
  [
      transferTransaction.toAggregate(multisigAccount),
  ],
  NetworkType.MIJIN_TEST,
  [],
);

initiator.signTransactionWithCosignatories(aggregateTransaction, cosignatories);

The signTransactionWithCosignatories function in AggregateTransaction class is internal and that function can only be accessed from the Account class.

@dgarcia360 @aleixmorgadas please review.

from symbol-docs.

dgarcia360 avatar dgarcia360 commented on May 27, 2024

Thanks @gimyboya for contributing to NEM2-Docs - I have tested the code using a 2-of-2 multisig, and it is working.

You could test it as well by announcing the transaction:

const transactionHttp = new TransactionHttp('http://localhost:3000');

// announce signed transaction
transactionHttp.announce(signedTransaction).subscribe(
    x => console.log(x),
    err => console.error(err)
);

and monitoring confirmed transactions using nem2-cli:

nem2-cli monitor confirmed -a

I'm willing to create a guide explaining how to make participants cosign the aggregate transaction offline. Meaning not using NEM network nor having all the required private keys.

The idea would be the following:

  • Initiator sign the aggregate transaction.
  • The initiator sends offline (could be through their server) the aggregate transaction to each participant.
  • Each participant signs individually.
  • Initiator creates a new SignedTransaction composing all the cosignatures and announces it.

Right now, I'm not 100% sure if that would be possible at the moment @aleixmorgadas . We'll keep you posted.

from symbol-docs.

khawarizmus avatar khawarizmus commented on May 27, 2024

Thank you for reviewing the code @dgarcia360 I will have to test it eventually..
I will look into your second example later on when i am free.

from symbol-docs.

dgarcia360 avatar dgarcia360 commented on May 27, 2024

This issue is being discussed here: symbol/symbol-sdk-typescript-javascript#112

from symbol-docs.

dgarcia360 avatar dgarcia360 commented on May 27, 2024

Implementation by @rg911 https://github.com/nemtech/nem2-sdk-typescript-javascript/blob/e11205c9068f03841d892964328a268e9eac18a6/e2e/infrastructure/TransactionHttp.spec.ts#L1646

from symbol-docs.

dgarcia360 avatar dgarcia360 commented on May 27, 2024

@matthewkim93 Adapted the code shared to use it in the guide https://gist.github.com/dgarcia360/24a074a3540bae1105c468f7f2ab39c3

from symbol-docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.