Blink Pay sdk provides the core functionality of creating, signing and verifying transaction in order to interact with the Blink API.
interface IPaymentInformation {
amount: number;
resourceId: string;
offerId: string;
dstAccount: string;
}
The fields inside the IPaymentInformation interface serve the following purpose:
-
amount : number
- The price of the resource that will be sold -
resourceId: string
- A unique identifier of the resource that is being sold -
offerId: string
- A secondary identifier used in case a resource that was previously sold needs an update ( e.g the same resource will be sold at different price at a later point ) -
dstAccount: string
- The address associated with the merchant ( or the addresses where the money will delivered )
interface BlinkPayment {
paymentInfo: IPaymentInformation;
paymentInfoSignature: string;
merchantPublicKey: string;
}
The fields inside the BlinkPayment interface serve the following purpose:
-
paymentInfo: IPaymentInformation
- Nested field of payment information -
paymentInfoSignature
- The signature of the fieldpaymentInfo
with the merchant private key -
merchantPublicKey
- The public key of the merchant
For signing the sdk provides the signPayment
and signPaymentInformation
functions.
signPayment
/**
* Creates a payment request object following the {IBlinkPayment} format.
* This object represents a payment request with the given payment information
* @param {IPaymentInformation} paymentInformation - The resource information ( e.g amount, id, etc. )
* @param {string} privateKey - The private key of the signer in hexadecimal format
* @param {string,undefined} publicKey - The public key of signer in hexadecimal format ( optional )
*
* @returns {BlinkPayment}
*/
const signPayment = (paymentInformation: IPaymentInformation, privateKey: string, publicKey?: string) : BlinkPayment
signPaymentInformation
/**
* Creates a payment request object following the {BlinkPayment} format given the payment information explicitly.
* @param {number} amount - The price of the resource
* @param {string} destinationAccount - The address associated with the merchant
* ( or the addresses where the money will delivered )
* @param {string} resourceId - A unique identifier of the resourced that is being sold
* @param {string} offerId - A secondary identifier used in case the unique resource need an update
* ( e.g the same resource will be sold at different price at a later point )
* @param {string} privateKey - The private key of the signer in hexadecimal format
* @param {string,undefined} publicKey - The public key of signer in hexadecimal format ( optional )
*
* @returns {BlinkPayment}
*/
export const signPaymentInformation = (amount: number, destinationAccount: string,
resourceId: string, offerId: string,
privateKey: string, publicKey?: string): BlinkPayment
verifySignedPayment
/**
* Verify that a payment was signed by the Blink network
* @param {string} payment - A base64 encoded string that is the payment information sent in the {IBlinkPayment} format.
* @param {string} paymentSignature - The signature of the payment information with the Blink private key
* @param {string} blinkPublicKey - The public key of Blink
*
* @returns {boolean}
*/
export const verifySignedPayment = (payment: string, paymentSignature: string, blinkPublicKey: string): boolean