Skip to content
A TypeScript/JavaScript implementation of SEP-0007 style Stellar URIs.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
.github
.vscode
demo
src
.gitignore
.npmignore
.prettierignore
CHANGELOG.md
LICENSE
README.md
package.json
tsconfig.json
tsconfig.module.json
tslint.json
yarn.lock

README.md

@stellarguard/stellar-uri

Latest Version NodeJS Support

A TypeScript/JavaScript implementation of SEP-0007 style Stellar URIs for the browser or NodeJS.

Note: to use this package your in the browser it must support the URL interface. If you would like to use it in a version not listed here consider using a polyfill.

Installation

npm install @stellarguard/stellar-uri --save
# or
yarn add @stellarguard/stellar-uri

Examples

See a live demo

Parsing a URI string and extracting the transaction

import { parseStellarUri } from '@stellarguard/stellar-uri';
import { Transaction } from 'stellar-sdk';

const uri = parseStellarUri(
  'web+stellar:tx?xdr=AAAAAP%2Byw%2BZEuNg533pUmwlYxfrq6%2FBoMJqiJ8vuQhf6rHWmAAAAZAB8NHAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAA%2F7LD5kS42DnfelSbCVjF%2Burr8GgwmqIny%2B5CF%2FqsdaYAAAAAAAAAAACYloAAAAAAAAAAAA'
);

const transaction = new Transaction(uri.xdr);

Creating and signing a transaction URI

import { TransactionStellarUri } from '@stellarguard/stellar-uri';
import { Transaction } from 'stellar-sdk';

const transaction = buildStellarTransaction(); // a StellarSdk.Transaction

const uri = TransactionStellarUri.forTransaction(transaction);
uri.msg = 'hello from me';
uri.originDomain = 'example.com';
uri.addSignature(mySecretKey); // example.com's URI_REQUEST_SIGNING_KEY

uri.toString(); // web+stellar:tx?xdr=...&msg=hello+from+me&origin_domain=example.com&signature=...

Verifying a signature

import { parseStellarUri } from '@stellarguard/stellar-uri';
import { Transaction } from 'stellar-sdk';

const uri = parseStellarUri(
  'web+stellar:pay?destination=GCALNQQBXAPZ2WIRSDDBMSTAKCUH5SG6U76YBFLQLIXJTF7FE5AX7AOO&amount=120.1234567&memo=skdjfasf&msg=pay%20me%20with%20lumens&origin_domain=someDomain.com&signature=JTlGMGzxUv90P2SWxUY9xo%2BLlbXaDloend6gkpyylY8X4bUNf6%2F9mFTMJs7JKqSDPRtejlK1kQvrsJfRZSJeAQ%3D%3D'
);

uri.verifySignature().then(isVerified => {
  if (isVerified) {
    // show origin domain
  } else {
    // something is wrong, warn the user
  }
});

QR Codes

This library does not handle generating a QR code for the Stellar URI.

Consider using an existing solution such as https://www.npmjs.com/package/qrcode.

The demo has an example of how that could be accomplished.

You can’t perform that action at this time.