Skip to content

Commit

Permalink
Merge pull request #27 from CityOfZion/CU-86a12v3tv
Browse files Browse the repository at this point in the history
CU-86a12v3tv - Fix decrypt on example wallet, it has a buffer problem
  • Loading branch information
melanke authored Nov 27, 2023
2 parents cb962eb + 8dd223e commit cfad038
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/neon-dappkit",
"comment": "Changes were made to methods that take Buffer as a parameter to ensure that the parameter is in fact Buffer",
"type": "patch"
}
],
"packageName": "@cityofzion/neon-dappkit"
}
6 changes: 3 additions & 3 deletions packages/neon-dappkit/src/NeonSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ export class NeonSigner implements Neo3Signer {
const macKey = hash.subarray(32)

const cipher = crypto.createCipheriv('aes-256-cbc', encryptionKey, iv)
const firstChunk = cipher.update(messageBuffer)
const firstChunk = cipher.update(Buffer.from(messageBuffer))
const secondChunk = cipher.final()
const ciphertext = Buffer.concat([firstChunk, secondChunk])

const dataToMac = Buffer.concat([iv, Buffer.from(ephemPublicKey, 'hex'), ciphertext])

const hmacSha = crypto.createHmac('sha256', macKey).update(dataToMac).digest()
const hmacSha = crypto.createHmac('sha256', Buffer.from(macKey)).update(dataToMac).digest()
const mac = Buffer.from(hmacSha)

return {
Expand Down Expand Up @@ -146,7 +146,7 @@ export class NeonSigner implements Neo3Signer {
Buffer.from(payload.ephemPublicKey, 'hex'),
Buffer.from(payload.cipherText, 'hex'),
])
const realMac = crypto.createHmac('sha256', macKey).update(dataToMac).digest()
const realMac = crypto.createHmac('sha256', Buffer.from(macKey)).update(dataToMac).digest()

if (payload.dataTag !== realMac.toString('hex')) {
throw new Error('invalid payload: hmac misalignment')
Expand Down

0 comments on commit cfad038

Please sign in to comment.