Skip to content

signStructuredData not in line with SIP018 specification #225

Closed
@MarvinJanssen

Description

@MarvinJanssen

Looking at signStructuredMessage, I noticed that although it signs Clarity Values, it is missing parts of the specification thus resulting in different signatures.

async function signPayload(payload: StructuredDataSignaturePayload, privateKey: string) {
const tokenSigner = new TokenSigner('ES256k', privateKey);
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
return tokenSigner.signAsync({
...payload,
message: serializeCV(payload.message).toString('hex'),
} as any);
}
export async function signStructuredMessage(options: StructuredDataSignatureRequestOptions) {
const { userSession, ..._options } = options;
const { privateKey, publicKey } = getKeys(userSession);
const payload: StructuredDataSignaturePayload = {
..._options,
publicKey,
};
return signPayload(payload, privateKey);
}

As per the current draft:
https://github.com/stacksgov/sips/blob/48a8493f19702a14258db5730fece837cd783b7a/sips/sip-018/sip-018-signed-structured-data.md#formal-specification

  • signStructuredData(D, K) = sign(messageHash(D), K), where:
  • messageHash(D) = sha256(structuredDataPrefix || domainHash || structuredDataHash(D)).

The domain tuple CV and payload CV should therefore be supplied separately. The prefix is 0x534950303138.

The domain tuple CV at the bare minimum requires:

{
	name: (string-ascii len)
	version: (string-ascii len)
	chain-id: uint
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Released or closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions