MCPcopy Index your code
hub / github.com/NoteProtocol/NoteWallet / checkContentSig

Function checkContentSig

src/note.ts:117–143  ·  view source on GitHub ↗
(
  content: Buffer,
  signature: string,
  publicKey: string
)

Source from the content-addressed store, hash-verified

115
116// Check signature to prevent data forgery, return true or false
117export function checkContentSig(
118 content: Buffer,
119 signature: string,
120 publicKey: string
121) {
122 // NOTE v2.0 signature check. A compressed signature
123 const msg = new bitcore.Message(content.toString("hex"));
124 // Get output signature
125 const isValid = msg._verify(
126 new bitcore.PublicKey(publicKey),
127 bitcore.crypto.Signature.fromCompact(Buffer.from(signature, "hex"))
128 );
129 if (isValid) {
130 return true;
131 }
132 // NOTE v1.0 signature check. An uncompressed signature
133 const hash = hash256(content);
134 const sig = bitcore.crypto.Signature.fromCompact(
135 Buffer.from(signature, "hex")
136 );
137 // Verify signature using root address public key to ensure transaction is not forged
138 return bitcore.crypto.ECDSA.verify(
139 hash,
140 sig,
141 new bitcore.PublicKey(publicKey)
142 );
143}
144
145// Build note payload, if singleMode=true, put all data in data0
146export function buildNotePayload(data: string | object, singleMode = false) {

Callers

nothing calls this directly

Calls 1

hash256Function · 0.85

Tested by

no test coverage detected