11# State Transition SDK
22
3- An SDK for defining and managing the lifecycle of stateful assets on the Unicity Protocol .
3+ An SDK for managing assets on the Unicity Protocol, supporting off-chain state with on-chain security guarantees .
44
55## Overview
66
@@ -24,6 +24,8 @@ npm install @unicitylabs/state-transition-sdk
2424
2525## Quick Start
2626
27+ Note: for more complete examples, see further down in the [ Examples section] ( #examples ) or browse around in the [ tests folder] ( ./tests ) of this SDK.
28+
2729### Basic Usage
2830
2931Minting
@@ -106,6 +108,7 @@ The main SDK interface for token operations:
106108
107109- ` submitMintTransaction() ` - Create mint commitment
108110- ` submitTransaction() ` - Create transfer commitment
111+ - ` submitBurnTransactionForSplit() ` - Create burn commitment as the first step of a token split (the next and final step is the mint operation)
109112- ` createTransaction() ` - Create transactions from commitments
110113- ` finishTransaction() ` - Complete token transfers
111114- ` getTokenStatus() ` - Check token status via inclusion proofs
@@ -119,9 +122,10 @@ To use address sent by someone:
119122const address = await DirectAddress .fromJSON (' DIRECT://582200004d8489e2b1244335ad8784a23826228e653658a2ecdb0abc17baa143f4fe560d9c81365b' );
120123```
121124
122- To use address for minting or to send it someone, reference from predicate is needed :
125+ To obtain an address for minting, or for sending the address to someone, the address is calculated from a predicate reference. Such addresses add privacy and unlinkability in the case of the masked predicate :
123126``` typescript
124127const address = await DirectAddress .create (MaskedPredicate .calculateReference (/* Reference parameters */ ));
128+ console .log (address .toJSON ()) // --> DIRECT://582200004d8489e2b1244335ad8784a23826228e653658a2ecdb0abc17baa143f4fe560d9c81365b
125129```
126130
127131### Predicate System
@@ -184,11 +188,16 @@ J --> K[End]
184188## Architecture
185189
186190### Token Structure
191+
187192Tokens contain:
188- - ** tokenId** : Unique 256-bit identifier
189- - ** tokenType** : Token class identifier
193+ - ** id** : Unique 256-bit identifier
194+ - ** type** : Token class identifier
195+ - ** version** : Token format version
190196- ** predicate** : Current ownership condition
191- - ** data** : Token-specific data (value for fungible, name-tag for addressing)
197+ - ** coins** : Coins of various types and amounts owned by this token (the coins can also represent tokens from other blockchains)
198+ - ** nametagTokens** : Name tags for addressing
199+ - ** data** : Token-specific data
200+ - ** transactions** : The history of transactions performed with this token
192201
193202### Privacy Model
194203- ** Commitment-based** : Only cryptographic commitments published on-chain
@@ -212,7 +221,7 @@ npm run build
212221
213222### Testing
214223
215- Run unit and integrations tests.
224+ Run unit and integration tests.
216225NB! Integration tests require docker to be installed.
217226
218227``` bash
@@ -279,7 +288,7 @@ const mintCommitment = await client.submitMintTransaction(
279288 data .tokenData ,
280289 data .coinData ,
281290 data .salt ,
282- await new DataHasher (HashAlgorithm .SHA256 ).update (data .data ).digest (),
291+ await new DataHasher (HashAlgorithm .SHA256 ).update (data .stateData ).digest (),
283292 null
284293);
285294
@@ -293,14 +302,14 @@ const token = new Token(
293302 data .tokenType ,
294303 data .tokenData ,
295304 data .coinData ,
296- await TokenState .create (data .predicate , data .data ),
305+ await TokenState .create (data .predicate , data .stateData ),
297306 [mintTransaction ],
298307);
299308```
300309
301310### Token Transfer
302311
303- This example begins after the previous example: here we assume that the tokens have already been minted and we wish to send the tokens to a new recipient.
312+ This example begins after the previous example. Here we assume that the tokens have already been minted and we wish to send the tokens to a new recipient.
304313
305314Note that the examples here are using some utility functions and classes that are defined below in a separate section.
306315
@@ -356,7 +365,7 @@ const importedTransaction = await Transaction.fromJSON(
356365 new PredicateFactory (),
357366);
358367
359- // The receipient finishes the transaction with the recipient predicate
368+ // The recipient finishes the transaction with the recipient predicate
360369const updateToken = await client .finishTransaction (
361370 importedToken ,
362371 await TokenState .create (recipientPredicate , new TextEncoder ().encode (' my custom data' )),
@@ -400,7 +409,7 @@ const mintCommitment = await client.submitMintTransaction(
400409 mintTokenData .tokenData ,
401410 mintTokenData .coinData ,
402411 mintTokenData .salt ,
403- await new DataHasher (HashAlgorithm .SHA256 ).update (mintTokenData .data ).digest (),
412+ await new DataHasher (HashAlgorithm .SHA256 ).update (mintTokenData .stateData ).digest (),
404413 null ,
405414);
406415
@@ -414,7 +423,7 @@ const token = new Token(
414423 mintTokenData .tokenType ,
415424 mintTokenData .tokenData ,
416425 mintTokenData .coinData ,
417- await TokenState .create (mintTokenData .predicate , mintTokenData .data ),
426+ await TokenState .create (mintTokenData .predicate , mintTokenData .stateData ),
418427 [mintTransaction ],
419428);
420429
@@ -475,7 +484,7 @@ const splitTokens = await Promise.all(
475484 tokenData .tokenData ,
476485 tokenData .coinData ,
477486 tokenData .salt ,
478- await new DataHasher (HashAlgorithm .SHA256 ).update (tokenData .data ).digest (),
487+ await new DataHasher (HashAlgorithm .SHA256 ).update (tokenData .stateData ).digest (),
479488 new SplitProof (updatedToken , burnProofs ),
480489 );
481490 const mintTransaction = await client .createTransaction (
@@ -487,7 +496,7 @@ const splitTokens = await Promise.all(
487496 tokenData .tokenType ,
488497 tokenData .tokenData ,
489498 tokenData .coinData ,
490- await TokenState .create (tokenData .predicate , tokenData .data ),
499+ await TokenState .create (tokenData .predicate , tokenData .stateData ),
491500 [mintTransaction ],
492501 );
493502 }),
@@ -532,7 +541,7 @@ async function createMintData(secret: Uint8Array, coinData: TokenCoinData): Prom
532541 const tokenType = TokenType .create (crypto .getRandomValues (new Uint8Array (32 )));
533542 const tokenData = new TestTokenData (crypto .getRandomValues (new Uint8Array (32 )));
534543
535- const data = crypto .getRandomValues (new Uint8Array (32 ));
544+ const stateData = crypto .getRandomValues (new Uint8Array (32 ));
536545
537546 const salt = crypto .getRandomValues (new Uint8Array (32 ));
538547 const nonce = crypto .getRandomValues (new Uint8Array (32 ));
@@ -547,7 +556,7 @@ async function createMintData(secret: Uint8Array, coinData: TokenCoinData): Prom
547556
548557 return {
549558 coinData ,
550- data ,
559+ stateData ,
551560 nonce ,
552561 predicate ,
553562 salt ,
@@ -562,7 +571,7 @@ interface IMintData {
562571 tokenType: TokenType ;
563572 tokenData: TestTokenData ;
564573 coinData: TokenCoinData ;
565- data : Uint8Array ;
574+ stateData : Uint8Array ;
566575 salt: Uint8Array ;
567576 nonce: Uint8Array ;
568577 predicate: MaskedPredicate ;
0 commit comments