Skip to content

Commit 28e2ca3

Browse files
committed
fix(sdk-core): coins specific message sign validate
SC-2419
1 parent 2ac0b7b commit 28e2ca3

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import { BaseMessageBuilder, IMessage, MessageOptions, MessageStandardType } fro
66
* Builder for CIP-8 messages
77
*/
88
export class Cip8MessageBuilder extends BaseMessageBuilder {
9+
private static readonly MIDNIGHT_TNC_HASH = '31a6bab50a84b8439adcfb786bb2020f6807e6e8fda629b424110fc7bb1c6b8b';
10+
11+
/*
12+
* matches a message that starts with "STAR ", followed by a number,
13+
* then " to addr" or " to addr_test1", followed by a 50+ character alphanumeric address,
14+
* and ends with the midnight TnC hash
15+
*/
16+
private static readonly MIDNIGHT_GLACIER_DROP_CLAIM_MESSAGE_TEMPLATE = `STAR \\d+ to addr(?:1|_test1)[a-z0-9]{50,} ${Cip8MessageBuilder.MIDNIGHT_TNC_HASH}`;
917
/**
1018
* Base constructor.
1119
* @param _coinConfig BaseCoin from statics library
@@ -22,4 +30,15 @@ export class Cip8MessageBuilder extends BaseMessageBuilder {
2230
async buildMessage(options: MessageOptions): Promise<IMessage> {
2331
return new Cip8Message(options);
2432
}
33+
34+
/**
35+
* Validates the signable payload
36+
* @param message The message to validate
37+
* @returns A boolean indicating whether the signable payload is valid
38+
*/
39+
public validateSignablePayload(message: string | Buffer): boolean {
40+
const messageStr = Buffer.isBuffer(message) ? message.toString('utf8') : message;
41+
const regex = new RegExp(`^${Cip8MessageBuilder.MIDNIGHT_GLACIER_DROP_CLAIM_MESSAGE_TEMPLATE}$`, 's');
42+
return regex.test(messageStr);
43+
}
2544
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ export abstract class BaseMessageBuilder implements IMessageBuilder {
118118
return this;
119119
}
120120

121+
/**
122+
* Validates the signable payload
123+
* @param message The message to validate
124+
* @returns A boolean indicating whether the signable payload is valid
125+
*/
126+
public validateSignablePayload(message: string | Buffer): boolean {
127+
return true;
128+
}
129+
121130
/**
122131
* Builds a message using the previously set payload and metadata
123132
* @returns A Promise resolving to the built IMessage

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ export interface IMessage {
6161
*/
6262
getSignablePayload(): Promise<string | Buffer>;
6363

64+
/**
65+
* Validates the signable payload
66+
* @param message The message to validate
67+
* @returns A boolean indicating whether the signable payload is valid
68+
*/
69+
validateSignablePayload(message: string | Buffer): boolean;
70+
6471
/**
6572
* Creates a broadcastable message format that includes the signatures
6673
* Uses internal signatures and signers that were previously set

0 commit comments

Comments
 (0)