@albedo-link/intent
v0.12.0
Published
A lightweight browser wrapper for Albedo API that provides a promise-based interface for all supported intents.
Downloads
2,939
Maintainers
Readme
Intent interface module for Albedo
This library is a lightweight browser wrapper for Albedo API that provides a promise-based interface for all supported intents.
Installation
npm i -S @albedo-link/intent
Usage
Setup
import albedo from '@albedo-link/intent'
Intents
Intent public_key
- View public key
Requests account public key. It's a simple way of authentication for Stellar-based applications. The response ensures that a user owns the corresponding secret key.
Parameters
token
(string) - (optional) Verification token generated by the application (should be unique or random).callback
(string) - (optional) Optional URL callback where Albedo will POST a signed token and public key.require_existing
(boolean) - (optional) Allow existing Albedo accounts only.
Returns
pubkey
(string) - User-selected public key.signed_message
(string) - HEX-encoded authentication message derived from the public key and verification token.signature
(string) - HEX-encoded ED25519 signature of the authentication message that can be further used to verify user's keypair ownership.
Example
albedo.publicKey({
token: 'r9gbUuThXLr/wOrg2dxWHOO4DQsvQsTpkv1OtfETB3c='
})
.then(res => console.log(res))
Intent sign_message
- Sign text message
Requests arbitrary message signing. Can be used to implement identity/ownership verification.
Parameters
message
(string) - (required) Text message to sign.pubkey
(string) - (optional) Specific public key requested by the application.callback
(string) - (optional) Optional URL callback where Albedo will POST a signed message.
Returns
pubkey
(string) - User-selected public key.original_message
(string) - Text message to sign from request.signed_message
(string) - HEX-encoded message derived from the public key and original message.message_signature
(string) - HEX-encoded ED25519 signature of the signed message.
Example
albedo.signMessage({
message: 'Alice doesn\'t trust Bob'
})
.then(res => console.log(res))
Intent tx
- Sign transaction
Requests a signature for the transaction. Returns the signed transaction envelope that can be submitted to the network or used for multi-sig coordination.
Parameters
xdr
(string) - (required) XDR-encoded transaction envelope to sign.pubkey
(string) - (optional) Specific public key requested by the application.network
(string) - (optional) Stellar network identifier.callback
(string) - (optional) Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.description
(string) - (optional) Optional human-friendly short transaction description provided by developers.submit
(boolean) - (optional) If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.
Returns
xdr
(string) - XDR-encoded transaction envelope from request.tx_hash
(string) - HEX-encoded transaction hash.signed_envelope_xdr
(string) - XDR-encoded transaction envelope with new signatures.network
(string) - Stellar network identifier.result
(object) - Optional response from Horizon if the transaction has been submitted automatically.
Example
albedo.tx({
xdr: 'AAAAALPZeTF.......B0dpb99l'
})
.then(res => console.log(res))
Intent pay
- Make payment
Requests a payment from a user. Works with any Stellar asset, supports transaction memo.
Parameters
amount
(string) - (required) Requested payment amount.destination
(string) - (required) Payment destination address.asset_code
(string) - (optional) Asset code (skip for XLM).asset_issuer
(string) - (optional) Asset issuer (skip for XLM).memo
(string) - (optional) Transaction memo (required for exchanges and some anchors).memo_type
(string) - (optional) Transaction memo type.pubkey
(string) - (optional) Specific public key requested by the application.network
(string) - (optional) Stellar network identifier or private network passphrase.callback
(string) - (optional) Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.submit
(boolean) - (optional) If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.
Returns
amount
(string) - Payment amount from request.destination
(string) - Payment destination address from request.asset_code
(string) - Asset code from request.asset_issuer
(string) - Asset issuer from request.memo
(string) - Transaction memo from request.memo_type
(string) - Transaction memo type from request.tx_hash
(string) - HEX-encoded transaction hash.signed_envelope_xdr
(string) - XDR-encoded transaction envelope with new signatures.pubkey
(string) - User-selected public key.network
(string) - Stellar network identifier.result
(object) - Optional response from Horizon if the transaction has been submitted automatically.
Example
albedo.pay({
amount: '5',
asset_code: 'EURT',
asset_issuer: 'GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S'
})
.then(res => console.log(res))
Intent trust
- Establish trustline
Requests permission to create a trustline to a given Stellar asset. Gradually simplifies the process of creating trustlines for anchors, ICOs, and airdrops.
Parameters
asset_code
(string) - (required) Trustline asset code.asset_issuer
(string) - (required) Trustline asset issuer address.limit
(string) - (optional) Trust limit.memo
(string) - (optional) Transaction memo (required for exchanges and some anchors).memo_type
(string) - (optional) Transaction memo type.pubkey
(string) - (optional) Specific public key requested by the application.network
(string) - (optional) Stellar network identifier or private network passphrase.callback
(string) - (optional) Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.submit
(boolean) - (optional) If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.
Returns
asset_code
(string) - Trustline asset code from request.asset_issuer
(string) - Trustline asset issuer address from request.limit
(string) - Trust limit from request.tx_hash
(string) - HEX-encoded transaction hash.signed_envelope_xdr
(string) - XDR-encoded transaction envelope with new signatures.pubkey
(string) - User-selected public key.network
(string) - Stellar network identifier.result
(object) - Optional response from Horizon if the transaction has been submitted automatically.
Example
albedo.trust({
asset_code: 'EURT',
asset_issuer: 'GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S'
})
.then(res => console.log(res))
Intent exchange
- Swap tokens
Requests permission to buy tokens on Stellar DEX at market price.
Parameters
amount
(string) - (required) The amount of asset to buy.max_price
(string) - (required) Maximum price the user willing to pay.sell_asset_code
(string) - (optional) Asset code of the asset to sell.sell_asset_issuer
(string) - (optional) Issuer account of the asset to sell.buy_asset_code
(string) - (optional) Asset code of the asset to buy.buy_asset_issuer
(string) - (optional) Issuer account of the asset to buy.memo
(string) - (optional) Transaction memo (required for exchanges and some anchors).memo_type
(string) - (optional) Transaction memo type.pubkey
(string) - (optional) Specific public key requested by the application.network
(string) - (optional) Stellar network identifier or private network passphrase.callback
(string) - (optional) Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.submit
(boolean) - (optional) If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.
Returns
amount
(string) - The amount of asset to buy from request.max_price
(string) - Maximum price the user willing to pay from request.sell_asset_code
(string) - Asset code of the asset to sell from request.sell_asset_issuer
(string) - Issuer account of the asset to sell from request.buy_asset_code
(string) - Asset code of the asset to buy from request.buy_asset_issuer
(string) - Issuer account of the asset to buy from request.tx_hash
(string) - HEX-encoded transaction hash.signed_envelope_xdr
(string) - XDR-encoded transaction envelope with new signatures.pubkey
(string) - User-selected public key.network
(string) - Stellar network identifier.result
(object) - Optional response from Horizon if the transaction has been submitted automatically.
Example
albedo.exchange({
amount: '5',
max_price: '3.5',
sell_asset_code: 'USD',
sell_asset_issuer: 'GDUKMGUGDZQK6YHYA5Z6AY2G4XDSZPSZ3SW5UN3ARVMO6QSRDWP5YLEX',
buy_asset_code: 'EURT',
buy_asset_issuer: 'GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S'
})
.then(res => console.log(res))
Intent implicit_flow
- Implicit permissions
Requests temporary access token for one or more intents that can be used to execute actions without explicit confirmation from the user. In order to be executed implicitly, an implicit flow permissions for a given intent should be granted and "pubkey" parameter set.
Parameters
intents
(string|string[]) - (required) Requested implicit flow intents.network
(string) - (optional) Stellar network identifier or private network passphrase.
Returns
granted
(boolean) - Whether a user granted permissions or not.intents
(string[]) - Requested implicit flow intents.grants
(string[]) - Implicit flow intents that have been granted.session
(string) - Unique implicit session id.valid_until
(number) - Session expiration timestamp.pubkey
(string) - User-selected public key.network
(string) - Stellar network identifier.
Example
albedo.implicitFlow({
intents: 'tx,pay,trust,sign_message'
})
.then(res => console.log(res))
Intent manage_account
- Open account settings
Opens account settings window for a given account.
Parameters
pubkey
(string) - (required) Specific public key requested by the application.network
(string) - (optional) Stellar network identifier or private network passphrase.
Returns
pubkey
(string) - Public key from intent request.
Example
albedo.manageAccount()
.then(res => console.log(res))
Intent batch
- Intents batch
Requests execution of several tx intents bundled together. This intent is atomic – a user confirms or rejects all bundled requests at once, with the same account and the same Stellar network.
Parameters
intents
(object[]) - (required) Requested tx intents that should be executed together.pubkey
(string) - (optional) Specific public key requested by the application.network
(string) - (optional) Stellar network identifier or private network passphrase.
Returns
intents
(object[]) - Requested tx intents.results
(object[]) - Array of results for each requested intent.pubkey
(string) - User-selected public key.network
(string) - Stellar network identifier.
Example
albedo.batch({
intents: 'tx,pay,trust,sign_message'
})
.then(res => console.log(res))
Implicit session utils
Collection of helpers to simplify various operations in the implicit mode.
isImplicitSessionAllowed(intent, pubkey)
Checks whether an implicit session has been granted earlier for an intent + pubkey pair.
Parameters
intent
(string) - (required) Intent to check.pubkey
(string) - (required) Public key of the account which granted access.
Returns
true/false
Example
const isAllowed = albedo.isImplicitSessionAllowed(
'tx',
'GBQW4KLMRXIMSDWBEWX4AWQKWYW7R3E7SFPSHTUDTFFT22NNUC6COL72'
)
listImplicitSessions()
Enumerates all currently active implicit sessions.
Returns
- An array of active session descriptors.
Example
for (let session of albedo.listImplicitSessions()){
console.log(session.pubkey, session.valid_until, session.grants)
}
forgetImplicitSession(pubkey)
Revokes session permission granted for an account.
Parameters
pubkey
(string) - (required) Public key of the account which granted access.
Example
const pubkey = 'GBQW4KLMRXIMSDWBEWX4AWQKWYW7R3E7SFPSHTUDTFFT22NNUC6COL72'
albedo.forgetImplicitSession(pubkey)
console.log(albedo.listImplicitSessions().some(s => s.pubkey === pubkey))
Development
To create UMD library bundle, run the following NPM script:
npm run build
It will also automatically update examples and parameters definitions for all available intents.
Running tests:
npm run test