Skip to content

Commit 08ab8df

Browse files
committed
feat(sdk-core): use common isMessageWhitelisted() function
TICKET: SC-2419
1 parent b5dbd70 commit 08ab8df

File tree

22 files changed

+53
-46
lines changed

22 files changed

+53
-46
lines changed

examples/ts/build-message.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
*/
99

1010
import {BitGoAPI} from '@bitgo/sdk-api';
11-
import {MessageStandardType} from "@bitgo/sdk-core";
11+
import {MessageStandardType, getMidnightGlacierDropMsg} from "@bitgo/sdk-core";
1212
import {Hteth} from "@bitgo/sdk-coin-eth";
13-
import {MIDNIGHT_TNC_HASH} from "@bitgo/account-lib";
1413
require('dotenv').config({ path: '../../.env' });
1514

1615
const bitgo = new BitGoAPI({
@@ -30,7 +29,8 @@ async function main() {
3029
console.log(`Wallet label: ${wallet.label()}`);
3130

3231
const adaTestnetDestinationAddress = 'addr_test1vz7xs7ceu4xx9n5xn57lfe86vrwddqpp77vjwq5ptlkh49cqy3wur';
33-
const testnetMessageRaw = `STAR 12345678 to ${adaTestnetDestinationAddress} ${MIDNIGHT_TNC_HASH}`;
32+
const allocationAmt = 12345678;
33+
const testnetMessageRaw = getMidnightGlacierDropMsg(adaTestnetDestinationAddress, allocationAmt);
3434

3535
const txRequest = await wallet.buildSignMessageRequest({
3636
message: {

examples/ts/sign-message.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
* Copyright 2025, BitGo, Inc. All Rights Reserved.
55
*/
66
import { BitGo } from 'bitgo';
7-
import { MessageStandardType } from '@bitgo/sdk-core';
8-
import { MIDNIGHT_TNC_HASH } from "@bitgo/account-lib";
7+
import { getMidnightGlacierDropMsg, MessageStandardType } from '@bitgo/sdk-core';
98

109
const bitgo = new BitGo({ env: 'test' });
1110

@@ -20,7 +19,8 @@ async function signMessage(): Promise<void> {
2019
const walletInstance = await basecoin.wallets().get({ id: walletId });
2120

2221
const adaTestnetDestinationAddress = 'addr_test1vz7xs7ceu4xx9n5xn57lfe86vrwddqpp77vjwq5ptlkh49cqy3wur';
23-
const testnetMessageRaw = `STAR 12345678 to ${adaTestnetDestinationAddress} ${MIDNIGHT_TNC_HASH}`;
22+
const allocationAmt = 12345678;
23+
const testnetMessageRaw = getMidnightGlacierDropMsg(adaTestnetDestinationAddress, allocationAmt);
2424

2525
const messageTxn = await walletInstance.signMessage({
2626
message: {

modules/account-lib/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,6 @@ export { Vet };
206206
import * as CosmosSharedCoin from '@bitgo/sdk-coin-cosmos';
207207
export { CosmosSharedCoin };
208208

209-
import { isMessageWhitelisted, MIDNIGHT_TNC_HASH, MIDNIGHT_GLACIER_DROP_CLAIM_MESSAGE_TEMPLATE } from './utils';
210-
export { isMessageWhitelisted, MIDNIGHT_TNC_HASH, MIDNIGHT_GLACIER_DROP_CLAIM_MESSAGE_TEMPLATE };
211-
212209
const coinBuilderMap = {
213210
trx: Trx.WrappedBuilder,
214211
ttrx: Trx.WrappedBuilder,

modules/account-lib/src/utils/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,3 @@ export function register(coinName: string): BaseUtils {
1818
}
1919
throw new NotSupported(`${coinName} util factory not supported`);
2020
}
21-
22-
export * from './messages';

modules/account-lib/test/unit/utils/messages/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import should from 'should';
22
import {
3-
MIDNIGHT_TNC_HASH,
3+
getMidnightGlacierDropMsg,
44
isMessageWhitelisted,
55
MIDNIGHT_GLACIER_DROP_CLAIM_MESSAGE_TEMPLATE,
6-
} from '../../../../src/utils';
6+
MIDNIGHT_TNC_HASH,
7+
} from '@bitgo/sdk-core';
78

89
describe('Message validation', () => {
910
describe('isMessageWhitelisted', () => {
@@ -12,17 +13,18 @@ describe('Message validation', () => {
1213
const adaTestnetDestinationAddress = 'addr_test1vz7xs7ceu4xx9n5xn57lfe86vrwddqpp77vjwq5ptlkh49cqy3wur';
1314
const adaMainnetDestinationAddress =
1415
'addr1q9k6u7lhf467y2f8skr2dafldx2npsd8fymq0mslnj0t44nd4ealwnt4ug5j0pvx5m6n76v4xrq6wjfkqlhpl8y7httq2m9cmu';
16+
const allocationAmt = 100;
1517

1618
it('should validate testnet message matching the Midnight glacier drop claim template', () => {
17-
const messageRaw = `STAR 100 to ${adaTestnetDestinationAddress} ${MIDNIGHT_TNC_HASH}`;
19+
const messageRaw = getMidnightGlacierDropMsg(adaTestnetDestinationAddress, allocationAmt);
1820

1921
const result = isMessageWhitelisted(whitelistedMessageTemplates, messageRaw);
2022

2123
should.equal(result, true);
2224
});
2325

2426
it('should validate mainnet message matching the Midnight glacier drop claim template', () => {
25-
const messageRaw = `STAR 100 to ${adaMainnetDestinationAddress} ${MIDNIGHT_TNC_HASH}`;
27+
const messageRaw = getMidnightGlacierDropMsg(adaMainnetDestinationAddress, allocationAmt);
2628

2729
const result = isMessageWhitelisted(whitelistedMessageTemplates, messageRaw);
2830

modules/account-lib/test/unit/verifyMessage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import should from 'should';
22
import * as accountLib from '../../src';
3-
import { MessageStandardType } from '@bitgo/sdk-core';
4-
import { MIDNIGHT_TNC_HASH } from '../../src/utils';
3+
import { getMidnightGlacierDropMsg, MessageStandardType } from '@bitgo/sdk-core';
54

65
describe('verifyMessage', () => {
76
const adaTestnetOriginAddress = 'addr_test1wz4h6068hs93n8j5ar88fgzz6sfnw8krng09xx0mmf36m8c7j9yap';
87
const adaTestnetDestinationAddress = 'addr_test1vz7xs7ceu4xx9n5xn57lfe86vrwddqpp77vjwq5ptlkh49cqy3wur';
9-
const testnetMessageRaw = `STAR 100 to ${adaTestnetDestinationAddress} ${MIDNIGHT_TNC_HASH}`;
8+
const allocationAmt = 100;
9+
const testnetMessageRaw = getMidnightGlacierDropMsg(adaTestnetDestinationAddress, allocationAmt);
1010

1111
describe('EIP191 Message', function () {
1212
const eip191MessageBuilder = accountLib

modules/sdk-coin-ada/src/lib/messages/cip8/cip8MessageBuilder.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { Cip8Message } from './cip8Message';
22
import { BaseCoin as CoinConfig } from '@bitgo/statics';
3-
import { BaseMessageBuilder, IMessage, MessageOptions, MessageStandardType } from '@bitgo/sdk-core';
4-
import { MIDNIGHT_GLACIER_DROP_CLAIM_MESSAGE_TEMPLATE } from '@bitgo/account-lib';
3+
import {
4+
BaseMessageBuilder,
5+
IMessage,
6+
MessageOptions,
7+
MessageStandardType,
8+
MIDNIGHT_GLACIER_DROP_CLAIM_MESSAGE_TEMPLATE,
9+
} from '@bitgo/sdk-core';
510

611
/**
712
* Builder for CIP-8 messages

modules/sdk-core/src/account-lib/baseCoin/messages/baseMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
MessageOptions,
66
MessagePayload,
77
MessageStandardType,
8-
} from '../../../bitgo';
8+
} from './messageTypes';
99
import { IMessage } from './iface';
1010
import { serializeSignatures, Signature } from '../iface';
1111

modules/sdk-core/src/account-lib/baseCoin/messages/baseMessageBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { BroadcastableMessage, MessageOptions, MessagePayload, MessageStandardType } from '../../../bitgo';
1+
import { BroadcastableMessage, MessageOptions, MessagePayload, MessageStandardType } from './messageTypes';
22
import { BaseCoin as CoinConfig } from '@bitgo/statics';
33
import { IMessage, IMessageBuilder } from './iface';
44
import { deserializeSignatures, Signature } from '../iface';
5-
import { isMessageWhitelisted } from '@bitgo/account-lib';
5+
import { isMessageWhitelisted } from './index';
66

77
/**
88
* Base Message Builder

modules/sdk-core/src/account-lib/baseCoin/messages/baseMessageBuilderFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BaseCoin as CoinConfig } from '@bitgo/statics';
22
import { IMessageBuilder, IMessageBuilderFactory } from './iface';
3-
import { BroadcastableMessage, MessageStandardType } from '../../../bitgo';
3+
import { BroadcastableMessage, MessageStandardType } from './messageTypes';
44
import { deserializeSignatures } from '../iface';
55

66
/**

0 commit comments

Comments
 (0)