Skip to content

Commit

Permalink
Merge pull request #414 from permaweb/twilson63/feat-relay-mode
Browse files Browse the repository at this point in the history
Twilson63/feat relay mode
  • Loading branch information
twilson63 authored Feb 11, 2025
2 parents 0593a0a + 121055d commit 41d35d8
Show file tree
Hide file tree
Showing 33 changed files with 1,747 additions and 910 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@permaweb/aos",
"version": "2.0.2",
"version": "2.0.3",
"private": true,
"repository": "https://github.com/permaweb/aos.git",
"license": "MIT",
Expand All @@ -22,7 +22,7 @@
"test-all": "yarn workspaces --parallel run test"
},
"dependencies": {
"@permaweb/aoconnect": "^0.0.59",
"@permaweb/aoconnect": "^0.0.67",
"arweave": "^1.15.1",
"chalk": "^5.3.0",
"figlet": "^1.7.0",
Expand All @@ -49,9 +49,9 @@
"standard": "^17.1.2"
},
"aos": {
"module": "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
"sqlite": "GuzQrkf50rBUqz3uUgjOIFOL1XmW9nSNysTBC-wyiWM",
"llama": "7eiZkMWDUQmY1SBIpumzYR5_XhVMbnjmA27Xbyt4QxU",
"version": "2.0.1"
"module": "JArYBF-D8q2OmZ4Mok00sD2Y_6SYEQ7Hjx-6VZ_jl3g",
"sqlite": "33d-3X8mpv6xYBlVB-eXMrPfH5Kzf6Hiwhcv0UA10sw",
"llama": "-izm2qwp0PrqEGzNNu6ZiGXOpj9KgZcPEbwb3PR4Vrs",
"version": "2.0.3"
}
}
}
12 changes: 6 additions & 6 deletions process/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@permaweb/ao-loader": "^0.0.37"
"@permaweb/ao-loader": "^0.0.44"
},
"scripts": {
"build": "ao build",
"test": "node --test --experimental-wasm-memory64",
"deploy": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 1-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.1 -t Name -v aos-lg-2.0.1",
"deploy-test": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 1-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.1 -t Name -v aos-test",
"deploy-sqlite": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 1-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.1 -t Name -v sqlite-lg-2.0.1",
"deploy-llama": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 16-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.1 -t Name -v llama-xxl-2.0.1 -t Extension -v WeaveDrive"
"deploy": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 1-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.3 -t Name -v aos-lg-2.0.3",
"deploy-test": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 1-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.3 -t Name -v aos-test",
"deploy-sqlite": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 1-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.3 -t Name -v sqlite-lg-2.0.3",
"deploy-llama": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 16-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.3 -t Name -v llama-xxl-2.0.3 -t Extension -v WeaveDrive"
}
}
}
21 changes: 12 additions & 9 deletions process/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ assignment.init(ao)
-- @table process
-- @field _version The version number of the process

local process = { _version = "2.0.1" }
local process = { _version = "2.0.3" }
-- The maximum number of messages to store in the inbox
local maxInboxCount = 10000

Expand Down Expand Up @@ -270,8 +270,8 @@ local function initializeState(msg, env)
Errors = Errors or {}
Inbox = Inbox or {}

-- temporary fix for Spawn
if not Owner then
-- Owner should only be assiged once
if env.Process.Id == msg.Id and not Owner then
local _from = findObject(env.Process.Tags, "name", "From-Process")
if _from then
Owner = _from.value
Expand Down Expand Up @@ -361,12 +361,15 @@ function process.handle(msg, _)

-- Added for aop6 boot loader
-- See: https://github.com/permaweb/aos/issues/342
Handlers.once("_boot",
function (msg)
return msg.Tags.Type == "Process" and Owner == msg.From
end,
require('.boot')(ao)
)
-- Only run bootloader when Process Message is First Message
if env.Process.Id == msg.Id then
Handlers.once("_boot",
function (msg)
return msg.Tags.Type == "Process" and Owner == msg.From
end,
require('.boot')(ao)
)
end

Handlers.append("_default", function () return true end, require('.default')(insertInbox))

Expand Down
67 changes: 42 additions & 25 deletions process/test/assignment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,26 @@ const env = {
}
}

async function init(handle) {
const {Memory} = await handle(null, {
Target: 'AOS',
From: 'FOOBAR',
Owner: 'FOOBAR',
'Block-Height': '999',
Id: 'AOS',
Module: 'WOOPAWOOPA',
Tags: [
{ name: 'Name', value: 'Thomas' }
]
}, env)
return Memory
}

describe('add the assignable MatchSpec', async () => {
test('by name', async () => {
const handle = await AoLoader(wasm, options)

const Memory = await init(handle)

const msg = {
Target: 'AOS',
Expand All @@ -39,14 +56,14 @@ describe('add the assignable MatchSpec', async () => {
`
}

const result = await handle(null, msg, env)
const result = await handle(Memory, msg, env)

assert.deepStrictEqual(JSON.parse(result.Messages[0].Data), { length: 1, name: 'foobar' })
})

test('update by name', async () => {
const handle = await AoLoader(wasm, options)

const Memory = await init(handle)
const msg = {
Target: 'AOS',
From: 'FOOBAR',
Expand All @@ -66,14 +83,14 @@ describe('add the assignable MatchSpec', async () => {
`
}

const result = await handle(null, msg, env)
const result = await handle(Memory, msg, env)

assert.deepStrictEqual(JSON.parse(result.Messages[0].Data), { length: 1, name: 'foobar' })
})

test('by index', async () => {
const handle = await AoLoader(wasm, options)

const Memory = await init(handle)
const msg = {
Target: 'AOS',
From: 'FOOBAR',
Expand All @@ -92,14 +109,14 @@ describe('add the assignable MatchSpec', async () => {
`
}

const result = await handle(null, msg, env)
const result = await handle(Memory, msg, env)

assert.deepStrictEqual(JSON.parse(result.Messages[0].Data), { length: 1 })
})

test('require name to be a string', async () => {
const handle = await AoLoader(wasm, options)

const Memory = await init(handle)
const msg = {
Target: 'AOS',
From: 'FOOBAR',
Expand All @@ -117,7 +134,7 @@ describe('add the assignable MatchSpec', async () => {
`
}

const result = await handle(null, msg, env)
const result = await handle(Memory, msg, env)

assert.ok(result.Error.includes('MatchSpec name MUST be a string'))
})
Expand All @@ -126,7 +143,7 @@ describe('add the assignable MatchSpec', async () => {
describe('remove the assignable MatchSpec', () => {
test('by name', async () => {
const handle = await AoLoader(wasm, options)

const Memory = await init(handle)
const msg = {
Target: 'AOS',
From: 'FOOBAR',
Expand All @@ -149,15 +166,15 @@ describe('remove the assignable MatchSpec', () => {
`
}

const result = await handle(null, msg, env)
const result = await handle(Memory, msg, env)

assert.deepStrictEqual(JSON.parse(result.Messages[0].Data), { length: 2, name: 'foobar' })
assert.deepStrictEqual(JSON.parse(result.Messages[1].Data), { length: 1 })
})

test('by index', async () => {
const handle = await AoLoader(wasm, options)

const Memory = await init(handle)
const msg = {
Target: 'AOS',
From: 'FOOBAR',
Expand All @@ -180,15 +197,15 @@ describe('remove the assignable MatchSpec', () => {
`
}

const result = await handle(null, msg, env)
const result = await handle(Memory, msg, env)

assert.deepStrictEqual(JSON.parse(result.Messages[0].Data), { length: 2, name: 'foobar' })
assert.deepStrictEqual(JSON.parse(result.Messages[1].Data), { length: 1, name: 'foobar' })
})

test('require name to be a string or number', async () => {
const handle = await AoLoader(wasm, options)

const Memory = await init(handle)
const msg = {
Target: 'AOS',
From: 'FOOBAR',
Expand All @@ -206,15 +223,15 @@ describe('remove the assignable MatchSpec', () => {
`
}

const result = await handle(null, msg, env)
const result = await handle(Memory, msg, env)
assert.ok(result.Error.includes('index MUST be a number'))
})
})

describe('determine whether the msg is an assignment or not', () => {
test('is an assignment', async () => {
const handle = await AoLoader(wasm, options)

const start = await init(handle)
const addAssignableMsg = {
Target: 'AOS',
Owner: 'FOOBAR',
Expand All @@ -238,7 +255,7 @@ describe('determine whether the msg is an assignment or not', () => {
`
}

const { Memory } = await handle(null, addAssignableMsg, env)
const { Memory } = await handle(start, addAssignableMsg, env)

const msg = {
Target: 'NOT_AOS',
Expand All @@ -260,7 +277,7 @@ describe('determine whether the msg is an assignment or not', () => {

test('is NOT an assignment', async () => {
const handle = await AoLoader(wasm, options)

const start = await init(handle)
const addAssignableMsg = {
Target: 'AOS',
Owner: 'FOOBAR',
Expand All @@ -284,7 +301,7 @@ describe('determine whether the msg is an assignment or not', () => {
`
}

const { Memory } = await handle(null, addAssignableMsg, env)
const { Memory } = await handle(start, addAssignableMsg, env)

const msg = {
Target: 'AOS',
Expand All @@ -309,7 +326,7 @@ describe('determine whether the msg is an assignment or not', () => {
describe('run handles on assignment based on assignables configured', () => {
test('at least 1 assignable allows specific assignment', async () => {
const handle = await AoLoader(wasm, options)

const start = await init(handle)
const addAssignableMsg = {
Target: 'AOS',
Owner: 'FOOBAR',
Expand All @@ -327,7 +344,7 @@ describe('run handles on assignment based on assignables configured', () => {
`
}

const { Memory } = await handle(null, addAssignableMsg, env)
const { Memory } = await handle(start, addAssignableMsg, env)

const msg = {
Target: 'NOT_AOS',
Expand All @@ -349,7 +366,7 @@ describe('run handles on assignment based on assignables configured', () => {

test('assignables do NOT allow specific assignment', async () => {
const handle = await AoLoader(wasm, options)

const start = await init(handle)
const addAssignableMsg = {
Target: 'AOS',
Owner: 'FOOBAR',
Expand All @@ -367,7 +384,7 @@ describe('run handles on assignment based on assignables configured', () => {
`
}

const { Memory } = await handle(null, addAssignableMsg, env)
const { Memory } = await handle(start, addAssignableMsg, env)

const msg = {
Target: 'NOT_AOS',
Expand All @@ -389,7 +406,7 @@ describe('run handles on assignment based on assignables configured', () => {

test('assignable does NOT allow specific assignment', async () => {
const handle = await AoLoader(wasm, options)

const start = await init(handle)
const addAssignableMsg = {
Target: 'AOS',
Owner: 'FOOBAR',
Expand All @@ -406,7 +423,7 @@ describe('run handles on assignment based on assignables configured', () => {
`
}

const { Memory } = await handle(null, addAssignableMsg, env)
const { Memory } = await handle(start, addAssignableMsg, env)

const msg = {
Target: 'NOT_AOS',
Expand All @@ -428,7 +445,7 @@ describe('run handles on assignment based on assignables configured', () => {

test('no assignables defaults to no assignments allowed', async () => {
const handle = await AoLoader(wasm, options)

const start = await init(handle)
const msg = {
Target: 'NOT_AOS',
Owner: 'FOOBAR',
Expand All @@ -443,7 +460,7 @@ describe('run handles on assignment based on assignables configured', () => {
Data: '2 + 2'
}

const result = await handle(null, msg, env)
const result = await handle(start, msg, env)
assert.deepStrictEqual(result.Messages[0].Data, 'Assignment is not trusted by this process!')
})
})
37 changes: 28 additions & 9 deletions process/test/crypto/cipher/aes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,35 @@ import fs from 'fs';
const wasm = fs.readFileSync('./process.wasm');
const options = { format: "wasm64-unknown-emscripten-draft_2024_02_15", computeLimit: 100247047330 }

const env = {
Process: {
Id: 'AOS',
Owner: 'FOOBAR',
Tags: [
{ name: 'Name', value: 'Thomas' }
]
}
}

async function init(handle) {
const {Memory} = await handle(null, {
Target: 'AOS',
From: 'FOOBAR',
Owner: 'FOOBAR',
'Block-Height': '999',
Id: 'AOS',
Module: 'WOOPAWOOPA',
Tags: [
{ name: 'Name', value: 'Thomas' }
]
}, env)
return Memory
}

test('run aes cipher successfully', async () => {
const handle = await AoLoader(wasm, options);
const env = {
Process: {
Id: 'AOS',
Owner: 'FOOBAR',
Tags: [{ name: 'Name', value: 'Thomas' }],
},
};

const start = await init(handle)

const results = [
// AES128 CBC Mode
"A3B9E6E1FBD9D46930E5F76807C84B8E", "616F0000000000000000000000000000",
Expand Down Expand Up @@ -79,7 +98,7 @@ test('run aes cipher successfully', async () => {
Data: data,
};

const result = await handle(null, msg, env);
const result = await handle(start, msg, env);

assert.equal(result.Output?.data, results.join(', '));
// assert.ok(result.GasUsed >= 3000000000)
Expand Down
Loading

0 comments on commit 41d35d8

Please sign in to comment.