Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE → algorand/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 HashMapsData2Value
Copyright (c) 2025 HashMapsData2Value

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 2 additions & 21 deletions algorand/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
# algorand
# Algorand-part of LeakSwap

Welcome to your new AlgoKit project!

This is your workspace root. A `workspace` in AlgoKit is an orchestrated collection of standalone projects (backends, smart contracts, frontend apps and etc).

By default, `projects_root_path` parameter is set to `projects`. Which instructs AlgoKit CLI to create a new directory under `projects` directory when new project is instantiated via `algokit init` at the root of the workspace.

## Getting Started

To get started refer to `README.md` files in respective sub-projects in the `projects` directory.

To learn more about algokit, visit [documentation](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/algokit.md).

### GitHub Codespaces

To get started execute:

1. `algokit generate devcontainer` - invoking this command from the root of this repository will create a `devcontainer.json` file with all the configuration needed to run this project in a GitHub codespace. [Run the repository inside a codespace](https://docs.github.com/en/codespaces/getting-started/quickstart) to get started.
2. `algokit init` - invoke this command inside a github codespace to launch an interactive wizard to guide you through the process of creating a new AlgoKit project

Powered by [Copier templates](https://copier.readthedocs.io/en/stable/).
Note that everything in this folder is licensed under MIT license.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { registerDebugEventHandlers } from '@algorandfoundation/algokit-utils-de
import { algorandFixture } from '@algorandfoundation/algokit-utils/testing'
import { beforeAll, beforeEach, describe, test, expect } from 'vitest'
import { LeakSwapClient, LeakSwapFactory } from '../artifacts/leak_swap/LeakSwapClient'
import { extractScalarFromLeakySignature, genScalar, getPK, leakySignature } from './toChocoBox'
// import { genScalar } from '../../../../../leakswap-utils/src/algorand-utils'
import { genPrivateSpendKey } from '../../../../../leakswap-utils/src/monero-utils'
import { extractScalarFromLeakySignature, hexToUint8Array, getPK, leakySign } from '../../../../../leakswap-utils/src/common'
import { Account, Address, Algodv2 } from 'algosdk'
import { IndexerClient } from 'algosdk/dist/types/client/v2/indexer/indexer'
import { TransactionSignerAccount } from '@algorandfoundation/algokit-utils/types/account'
Expand Down Expand Up @@ -58,8 +60,8 @@ describe('LeakSwap contract', () => {

// TODO: replace with 0 Algo initial funds, funding by calling funder LSIG
const xinAlgoAccount = (await localnet.context.generateAccount({ initialFunds: (10).algo(), suppressLog: true }))
const aliXternalSK = genScalar()
const xinXternalSK = genScalar()
const aliXternalSK = hexToUint8Array(genPrivateSpendKey())//genScalar()
const xinXternalSK = hexToUint8Array(genPrivateSpendKey())//genScalar()

const leakySwapCreateParams: LeakSwapCreateAppParams = {
aliXternalPK: getPK(aliXternalSK),
Expand Down Expand Up @@ -89,7 +91,7 @@ describe('LeakSwap contract', () => {
localnet.algorand.client.algod,
client.appId,
xinAlgoAccount,
leakySignature( // Xin's leaky signature leaks his xternal secret key, on purrpose
leakySign( // Xin's leaky signature leaks his xternal secret key, on purrpose
client.appAddress.publicKey,
xinXternalSK,
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-te
import { describe, expect, it } from 'vitest'
import { Bytes } from '@algorandfoundation/algorand-typescript'
import { LeakSwap } from './contract.algo'
import { genScalar, getPK, leakySignature } from './toChocoBox'
// import { genScalar } from '../../../../../leakswap-utils/src/algorand-utils'
import { genPrivateSpendKey } from '../../../../../leakswap-utils/src/monero-utils'
import { getPK, leakySign, hexToUint8Array } from '../../../../../leakswap-utils/src/common'
import { ed25519 } from '@noble/curves/ed25519'

export enum LeakSwapState {
Expand All @@ -16,19 +18,18 @@ describe('LeakSwap contract', () => {
const ctx = new TestExecutionContext()
const aliAlgoAddr = ctx.defaultSender
const xinAlgoAddr = ctx.any.account()
const transferAmount = 1_000_000

it('test leakySignature method in contract', () => {
it('testleakySign method in contract', () => {
const contract = ctx.contract.create(LeakSwap)

const a = genScalar()
const a = hexToUint8Array(genPrivateSpendKey())
const pk = getPK(a);

// Fixed Contract Address
const hexString = '72a43709d7a9981bc3b37f700e56d3cdb295a5fb731085bcec398f48d0a4d436'
const messageBytes = Uint8Array.from(Buffer.from(hexString, 'hex'))

const signature = leakySignature(messageBytes, a)
const signature = leakySign(messageBytes, a)

contract.verifySignature(Bytes(signature), Bytes(pk))

Expand Down Expand Up @@ -65,9 +66,9 @@ describe('LeakSwap contract', () => {
it('LeakSwap: Simple Happy Path', async () => {
const contract = ctx.contract.create(LeakSwap)

const aliXternalSK = genScalar()
const aliXternalSK = hexToUint8Array(genPrivateSpendKey())
const aliXternalPK = getPK(aliXternalSK)
const xinXternalSK = genScalar()
const xinXternalSK = hexToUint8Array(genPrivateSpendKey())
const xinXternalPK = getPK(xinXternalSK)
const t0 = Date.now() + 3600 * 1000 // 1 hour from current time
const t1 = t0 + 1800 * 1000 // 30 minutes after t0
Expand All @@ -88,7 +89,7 @@ describe('LeakSwap contract', () => {
// * <-- Xin *does* lock up funds in the combined Monero account --> *

// Xin's leaky signature - convert contract address hex to bytes
const xinSignature = leakySignature(
const xinSignature = leakySign(
Buffer.from(ctx.ledger.getApplicationForContract(contract).address.bytes as unknown as string, 'hex'),
xinXternalSK
)
Expand All @@ -101,7 +102,7 @@ describe('LeakSwap contract', () => {

// Ali, maliciously, tries to call leakyRefund
// It should of course fail since the contract is in ready state
const aliSignature = leakySignature(
const aliSignature = leakySign(
Buffer.from(ctx.ledger.getApplicationForContract(contract).address.bytes as unknown as string, 'hex'),
aliXternalSK
)
Expand Down Expand Up @@ -139,9 +140,9 @@ describe('LeakSwap contract', () => {
it('LeakSwap: T0 TimeOut Path', async () => {
const contract = ctx.contract.create(LeakSwap)

const aliXternalSK = genScalar()
const aliXternalSK = hexToUint8Array(genPrivateSpendKey())
const aliXternalPK = getPK(aliXternalSK)
const xinXternalSK = genScalar()
const xinXternalSK = hexToUint8Array(genPrivateSpendKey())
const xinXternalPK = getPK(xinXternalSK)
const t0 = Date.now() + 3600 * 1000 // 1 hour from current time
const t1 = t0 + 1800 * 1000 // 30 minutes after t0
Expand All @@ -162,7 +163,7 @@ describe('LeakSwap contract', () => {
// * <-- Xin does or does not lock up funds in the combined Monero account --> *

// Xin's leaky signature - convert contract address hex to bytes
const xinSignature = leakySignature(
const xinSignature = leakySign(
Buffer.from(ctx.ledger.getApplicationForContract(contract).address.bytes as unknown as string, 'hex'),
xinXternalSK
)
Expand Down Expand Up @@ -196,7 +197,7 @@ describe('LeakSwap contract', () => {

// Ali, in a panic, tries to call leakyRefund
// This should fail since the contract has already passed t0
const aliSignature = leakySignature(
const aliSignature = leakySign(
Buffer.from(ctx.ledger.getApplicationForContract(contract).address.bytes as unknown as string, 'hex'),
aliXternalSK
)
Expand Down Expand Up @@ -224,9 +225,9 @@ describe('LeakSwap contract', () => {
it('LeakSwap: Ali Leaky Refunds', async () => {
const contract = ctx.contract.create(LeakSwap)

const aliXternalSK = genScalar()
const aliXternalSK = hexToUint8Array(genPrivateSpendKey())
const aliXternalPK = getPK(aliXternalSK)
const xinXternalSK = genScalar()
const xinXternalSK = hexToUint8Array(genPrivateSpendKey())
const xinXternalPK = getPK(xinXternalSK)
const t0 = Date.now() + 3600 * 1000 // 1 hour from current time
const t1 = t0 + 1800 * 1000 // 30 minutes after t0
Expand All @@ -247,7 +248,7 @@ describe('LeakSwap contract', () => {
// * <-- Xin does not lock up funds in the combined Monero account --> *

// Ali's leaky signature - convert contract address hex to bytes
const aliSignature = leakySignature(
const aliSignature = leakySign(
Buffer.from(ctx.ledger.getApplicationForContract(contract).address.bytes as unknown as string, 'hex'),
aliXternalSK
)
Expand All @@ -261,9 +262,9 @@ describe('LeakSwap contract', () => {
it('LeakSwap: T1 TimeOut PunishRefund Path', async () => {
const contract = ctx.contract.create(LeakSwap)

const aliXternalSK = genScalar()
const aliXternalSK = hexToUint8Array(genPrivateSpendKey())
const aliXternalPK = getPK(aliXternalSK)
const xinXternalSK = genScalar()
const xinXternalSK = hexToUint8Array(genPrivateSpendKey())
const xinXternalPK = getPK(xinXternalSK)
const t0 = Date.now() + 3600 * 1000 // 1 hour from current time
const t1 = t0 + 1800 * 1000 // 30 minutes after t0
Expand All @@ -289,7 +290,7 @@ describe('LeakSwap contract', () => {
// Now the contract should be in T1 passed state
expect(contract.getContractState()).toEqual(LeakSwapState.T1Passed)

const xinSignature = leakySignature(
const xinSignature = leakySign(
Buffer.from(ctx.ledger.getApplicationForContract(contract).address.bytes as unknown as string, 'hex'),
xinXternalSK
)
Expand Down
13 changes: 10 additions & 3 deletions algorand/projects/algorand/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"isolatedModules": true,
"noEmit": true
},
"include": ["smart_contracts/**/*.ts"],
"exclude": ["node_modules", "dist", "coverage"]
}
"include": [
"smart_contracts/**/*.ts",
"../../../leakswap-utils/src/algorand-utils.ts"
],
"exclude": [
"node_modules",
"dist",
"coverage"
]
}
2 changes: 2 additions & 0 deletions leakswap-utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
node_modules/*
7 changes: 7 additions & 0 deletions leakswap-utils/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
src/
test/
__tests__/
*.test.ts
*.spec.ts
*.log
tsconfig.json
9 changes: 9 additions & 0 deletions leakswap-utils/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Config } from 'jest';

const config: Config = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
};

export default config;
Loading