Skip to content

Commit

Permalink
hash the program of the template and perform a integrity check at run…
Browse files Browse the repository at this point in the history
… time for LSIG_TEMPLATE

Signed-off-by: ehanoc <[email protected]>
  • Loading branch information
ehanoc committed May 20, 2024
1 parent 9da409b commit ce69e2c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
5 changes: 0 additions & 5 deletions assets/arc-0060/arc60wallet.api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { randomBytes } from "crypto"
import { Arc60WalletApi, ERROR_DOESNT_MATCH_SCHEMA, ERROR_INVALID_SCOPE, ERROR_UNKNOWN_LSIG, ScopeType, StdSigData } from "./arc60wallet.api"
import { crypto_sign_verify_detached, ready } from "libsodium-wrappers-sumo"
import { sha512_256 } from "js-sha512"

describe('Test Suite Name', () => {

Expand Down Expand Up @@ -186,10 +185,6 @@ describe('Test Suite Name', () => {
hash: "866b786c4c36c22a9f2aab6bc51bdbfc81d2a645a5a1839f62b76f626f5fc9fe"
}

// sha512_256 lSigRequest hash
const lSigRequestHash: string = sha512_256(Buffer.from(JSON.stringify(lSigRequest), 'utf-8'))
console.log("lSigRequestHash: ", lSigRequestHash)

const publicKey: Uint8Array = await Arc60WalletApi.getPublicKey(seed)

const signData: StdSigData = {
Expand Down
8 changes: 3 additions & 5 deletions assets/arc-0060/arc60wallet.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as crypto from 'crypto'
import { readFileSync } from 'fs';
import path from 'path';
import Ajv, { JSONSchemaType } from 'ajv';
import sha512, { sha512_256 } from 'js-sha512'
import sha512 from 'js-sha512'
import axios, { AxiosResponse } from 'axios'
import * as util from 'util'

Expand Down Expand Up @@ -93,7 +93,7 @@ export class Arc60WalletApi {
* Known LSIG template hashes.
*/
static known_lsigs_template_hashes: string[] = [
"e6d0d81db76b663daa0b09281dada1db564898c9f3105efe8bfc7f63ffeaf360"
"866b786c4c36c22a9f2aab6bc51bdbfc81d2a645a5a1839f62b76f626f5fc9fe"
]

/**
Expand Down Expand Up @@ -194,10 +194,8 @@ export class Arc60WalletApi {
throw ERROR_UNKNOWN_LSIG;
}

const lsigRequestTemplateHash: string = sha512_256(decodedData)

// check if hash is one of the known hashes
if(!Arc60WalletApi.known_lsigs_template_hashes.includes(lsigRequestTemplateHash)) {
if(!Arc60WalletApi.known_lsigs_template_hashes.includes(hexProgramHash)) {
throw ERROR_UNKNOWN_LSIG;
}

Expand Down

0 comments on commit ce69e2c

Please sign in to comment.