@@ -5,6 +5,7 @@ import { Environments } from '../environments';
55
66const NUM_MESSAGES_PER_TRANSACTION = 2 ;
77const NUM_MESSAGES_PER_QUERY = 1000 ;
8+ export const MIDNIGHT_TNC_HASH = '31a6bab50a84b8439adcfb786bb2020f6807e6e8fda629b424110fc7bb1c6b8b' ;
89
910type MessageInfo = {
1011 message : string ;
@@ -38,23 +39,23 @@ export interface IMessageProvider {
3839 * handles the pagination and batching of messages, keeping a local cache of the unprocessed messages.
3940 */
4041export class MidnightMessageProvider implements IMessageProvider {
41- protected messageCache : MessageInfo [ ] ;
42+ protected unprocessedMessagesCache : MessageInfo [ ] ;
4243 protected network : utxolib . Network ;
4344 protected midnightClaimUrl : string ;
4445 protected prevId : string | undefined ;
4546 protected ranOnce = false ;
46- constructor ( private wallet : IWallet , private message : string ) {
47- this . messageCache = [ ] ;
47+ constructor ( private wallet : IWallet , private destinationAddress : string ) {
48+ this . unprocessedMessagesCache = [ ] ;
4849 this . network = utxolib . networks [ wallet . coin ( ) ] ;
4950 this . midnightClaimUrl = `${
5051 Environments [ wallet . bitgo . env ] . uri
5152 } /api/airdrop-claim/v1/midnight/claims/${ wallet . coin ( ) } /${ wallet . id ( ) } `;
5253 }
5354
5455 async getMessagesAndAddressesToSign ( ) : Promise < MessageInfo [ ] > {
55- if ( this . messageCache . length > 0 ) {
56- return this . messageCache . splice ( 0 , NUM_MESSAGES_PER_TRANSACTION ) ;
57- } else if ( this . messageCache . length === 0 && this . ranOnce && this . prevId === undefined ) {
56+ if ( this . unprocessedMessagesCache . length > 0 ) {
57+ return this . unprocessedMessagesCache . splice ( 0 , NUM_MESSAGES_PER_TRANSACTION ) ;
58+ } else if ( this . unprocessedMessagesCache . length === 0 && this . ranOnce && this . prevId === undefined ) {
5859 return [ ] ;
5960 }
6061
@@ -76,26 +77,33 @@ export class MidnightMessageProvider implements IMessageProvider {
7677 this . prevId = undefined ;
7778 }
7879
79- this . messageCache = response . claims . map ( ( claim : Claim ) => {
80+ this . unprocessedMessagesCache = response . claims . map ( ( claim : Claim ) => {
8081 if ( ! claim . originAddress ) {
8182 throw new Error ( `Claim ${ JSON . stringify ( claim ) } is missing originAddress` ) ;
8283 }
8384 return {
84- message : this . message ,
85+ // Midnight claim message format
86+ message : `STAR ${ claim . allocationAmount } to ${ this . destinationAddress } ${ MIDNIGHT_TNC_HASH } ` ,
8587 address : claim . originAddress ,
8688 } ;
8789 } ) ;
88- const toReturn = this . messageCache . splice ( 0 , NUM_MESSAGES_PER_TRANSACTION ) ;
90+ const toReturn = this . unprocessedMessagesCache . splice ( 0 , NUM_MESSAGES_PER_TRANSACTION ) ;
8991 return toReturn ;
9092 }
9193}
9294
95+ /**
96+ * Bulk signs BIP322 messages for the Midnight airdrop.
97+ * @param wallet The wallet to sign the messages with.
98+ * @param destinationAddress The ADA address the rewards will get sent to
99+ * @param walletPassphrase (Optional) The wallet passphrase of the wallet
100+ */
93101export async function bulkSignBip322MidnightMessages (
94102 wallet : IWallet ,
95- message : string ,
103+ destinationAddress : string ,
96104 walletPassphrase ?: string
97105) : Promise < BulkMessageResponse > {
98- const provider = new MidnightMessageProvider ( wallet , message ) ;
106+ const provider = new MidnightMessageProvider ( wallet , destinationAddress ) ;
99107 return bulkSignBip322MessagesWithProvider ( provider , wallet , walletPassphrase ) ;
100108}
101109
0 commit comments