Git Product home page Git Product logo

nem-swift-blockchain-lib's Introduction

Swift / Blockchain Library for NEM.io Platform

Java library to convert and send Swift Messages to NEM Blockchain and vice versa

Usage

Set up your Node first via app.properties.

The library uses the Builder Pattern to create and send transactions.

Set up your node connection

Create a app.properties file on your classpath and add the following:
node.endpoint.networkname=testnet
node.endpoint.protocol=http
node.endpoint.uri=<testnet node>
node.endpoint.port=7890

Encode and Gzip Swift File/Text

//	swift message
final String sampleSwiftMsg = "{1:F21FOOLHKH0AXXX0304009999}{4:{177:1608140809}{451:0}}{1:F01FOOLHKH0AXXX0304009999}{2:O9401609160814FOOLHKH0AXXX03040027341608141609N}{4:\n"
		+ ":20:USD940NO1\n" + ":21:123456/DEV\n" + ":25:USD234567\n" + ":28C:1/1\n" + ":60F:C160418USD672,\n"
		+ ":61:160827C642,S1032\n" + ":86:ANDY\n" + ":61:160827D42,S1032\n" + ":86:BANK CHARGES\n"
		+ ":62F:C160418USD1872,\n" + ":64:C160418USD1872,\n" + "-}{5:{CHK:0FEC1E4AEC53}{TNG:}}{S:{COP:S}}";

//	set the account 
final Account senderAccount = EntityFactory.buildAccountFromPrivateKey("<privatekey>");
final Account recipientAccount = EntityFactory.buildAccountFromPublicKey("<publickey>");

//	prepare the payload message.
SecureMessage message = SecureMessageSwiftPayloadEncoder.encodeAndGzipCompress(senderAccount, recipientAccount, sampleSwiftMsg);

// use the builder to build and send the transaction.
SwiftTransactionBuilder
	.sender(this.senderPrivateAccount)
	.recipient(this.recipientPublicAccount)
	.amount(0l)
	.attachment(AttachmentFactory.createTransferTransactionAttachment(message))
	.buildAndSendTransaction();
	

Decode Swift File/Text

//	 encrypted swift message
final String encryptedMessage = "c621b0e0a3f20523f60f9d99394e716e598c575b9f3c06a613b5d1483805dcb22c08e09de166ac08ebbf7c3f953dda74d634e60d81ba35059a53bb6662b624d7243315d3af013630f17f2b2120869a364e39152b35aa502067166cd80c215db3c023ec4c28c9438d33d0c75e15093bbb7d84154476288d49017918f3cc2f90d9734400c45283d258068c6d2b4db5c1243ff32d008bb92d8841455f38b611fa67ecc4afc0761a5ec3931c4875850d98d64d00e87a93f1284847b6d62390ead93f714784f658c6651ae56b1cb9684339ee654204bdef601e2df33f68d51463e58d2f4cdb5570a33084717f7b24c2bdf9e745d6154c0260182f59d7901d04131aa636dc3f368fb4622a5fb8e65fc24cd3f9";

//	set the account 
final Account senderAccount = EntityFactory.buildAccountFromPrivateKey("<privatekey>");
final Account recipientAccount = EntityFactory.buildAccountFromPublicKey("<publickey>");

//	Get the decoded message.
String decodedPayload = SecureMessageSwiftPayloadDecoder.decodeAndGzipUncompress(senderKeyPair, recipientKeyPairPriv,encryptedMessage);
	

Monitoring Incoming/Outgoing Transactions

Documentation to follow.

Testing

Run the JUnit Test cases using Maven or use it as a reference.

mvn test

To test the funtionality with real data, set the sender, recipient and multisig via the super class TransactionUnitTest class.

@Before // for encoding.
public void init() {
    this.setAccountMultisigAccountPublicKey(...);
    this.setAccountSenderPrivateKey(...);
    this.setAccountRecipientPublicKey(...);
}

@Before // for decoding.
public void init() {
    this.setAccountMultisigAccountPublicKey(...);
    this.setAccountSenderPublicKey(...);
    this.setAccountRecipientPrivateKey(...);
}

Build

Like any other maven project, just do the maven command below.

mvn clean install

Copyright (c) 2017

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.