Skip to content

Commit 5175d87

Browse files
committed
docs: update jsdoc
1 parent 2160c01 commit 5175d87

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

packages/evolution/src/core/SignData.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
/**
2-
* COSE (RFC 8152) message signing for Cardano (CIP-0030).
2+
* COSE (RFC 8152) message signing for Cardano.
33
*
4-
* This module provides a TypeScript implementation of @emurgo/cardano-message-signing-nodejs,
5-
* offering the complete CSL message signing API surface including:
6-
* - COSESign1Builder: Builder for creating COSE_Sign1 structures
7-
* - COSESign1: Signed message representation
8-
* - COSEKey: COSE key representation
9-
* - Headers: Protected and unprotected headers
10-
* - HeaderMap: Map of header labels to values
11-
* - Label: Header label representation
12-
* - EdDSA25519Key: Ed25519 key operations
4+
* Implements CIP-30 wallet API and CIP-8 message signing using COSE_Sign1 structures.
5+
* Compatible with all major Cardano wallets.
136
*
147
* @since 2.0.0
158
* @category Message Signing
@@ -568,7 +561,7 @@ export class COSEKey extends Schema.Class<COSEKey>("COSEKey")({
568561

569562
/**
570563
* CBOR bytes transformation schema for COSEKey.
571-
* Encodes COSEKey as a CBOR Map compatible with CSL/lucid-evolution.
564+
* Encodes COSEKey as a CBOR Map compatible with CSL.
572565
*
573566
* @since 2.0.0
574567
* @category Schemas
@@ -1076,13 +1069,17 @@ export const coseSign1BuilderNew = (
10761069
/**
10771070
* Payload type - raw binary data to be signed.
10781071
*
1072+
* The payload is NOT pre-hashed before signing (per CIP-8).
1073+
*
10791074
* @since 2.0.0
10801075
* @category Types
10811076
*/
10821077
export type Payload = Uint8Array
10831078

10841079
/**
1085-
* Signed message result.
1080+
* Signed message result (CIP-30 DataSignature format).
1081+
*
1082+
* Contains CBOR-encoded COSE_Sign1 (signature) and COSE_Key (public key).
10861083
*
10871084
* @since 2.0.0
10881085
* @category Types
@@ -1094,7 +1091,12 @@ export type SignedMessage = {
10941091

10951092
/**
10961093
* Sign data with a private key using COSE_Sign1.
1097-
* Compatible with lucid-evolution's sign_data implementation.
1094+
*
1095+
* Implements CIP-30 `api.signData()` specification. Creates a COSE_Sign1 structure with:
1096+
* - Protected headers: algorithm (EdDSA), address
1097+
* - Unprotected headers: hashed (false)
1098+
* - Payload: NOT pre-hashed
1099+
* - Returns CBOR-encoded COSE_Sign1 and COSE_Key
10981100
*
10991101
* @since 2.0.0
11001102
* @category API
@@ -1104,11 +1106,11 @@ export const signData = (
11041106
payload: Payload,
11051107
privateKey: PrivateKey.PrivateKey
11061108
): SignedMessage => {
1107-
// Create headers with algorithm and address (in protected headers like lucid-evolution)
1109+
// Create headers with algorithm and address in protected headers
11081110
const protectedHeaders = headerMapNew()
11091111
.setAlgorithmId(AlgorithmId.EdDSA)
11101112
.setHeader(labelFromText("address"), Bytes.fromHex(addressHex))
1111-
// Add "hashed": false to unprotected headers (lucid-evolution compatibility)
1113+
// Add "hashed": false to unprotected headers
11121114
const unprotectedHeaders = headerMapNew().setHeader(labelFromText("hashed"), false)
11131115
const headers = headersNew(protectedHeaders, unprotectedHeaders)
11141116

@@ -1127,7 +1129,7 @@ export const signData = (
11271129
// Encode to CBOR bytes
11281130
const signedBytes = Schema.encodeSync(COSESign1FromCBORBytes())(coseSign1)
11291131

1130-
// Build COSEKey compatible with lucid-evolution
1132+
// Build COSEKey
11311133
const vkey = VKey.fromPrivateKey(privateKey)
11321134
const ed25519Key = new EdDSA25519Key({ privateKey: undefined, publicKey: vkey }, { disableValidation: true })
11331135
const coseKey = ed25519Key.build()
@@ -1141,7 +1143,13 @@ export const signData = (
11411143

11421144
/**
11431145
* Verify a COSE_Sign1 signed message.
1144-
* Compatible with lucid-evolution's verifyData implementation.
1146+
*
1147+
* Validates CIP-30 signatures by verifying:
1148+
* - Payload matches signed data
1149+
* - Address matches protected headers
1150+
* - Algorithm is EdDSA
1151+
* - Public key hash matches provided key hash
1152+
* - Ed25519 signature is cryptographically valid
11451153
*
11461154
* @since 2.0.0
11471155
* @category API

0 commit comments

Comments
 (0)