Skip to content

Commit 8e7dd8e

Browse files
authored
fix: allow unmarshaling encrypted manifests (#1052)
* fix: allow unmarshaling encrypted manifests * test: improve testability
1 parent b8607d2 commit 8e7dd8e

File tree

11 files changed

+45
-28
lines changed

11 files changed

+45
-28
lines changed

jest.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import type { Config } from '@jest/types'
77
import { Dates, Types } from 'cafe-utility'
88

99
export default async (): Promise<Config.InitialOptions> => {
10-
Types.asString(process.env.JEST_BEE_FULL_URL, { name: 'JEST_BEE_FULL_URL' })
11-
Types.asString(process.env.JEST_BEE_LIGHT_URL, { name: 'JEST_BEE_LIGHT_URL' })
12-
Types.asString(process.env.JEST_BEE_ULTRA_LIGHT_URL, { name: 'JEST_BEE_ULTRA_LIGHT_URL' })
13-
Types.asHexString(process.env.JEST_FULL_BATCH_ID, { name: 'JEST_FULL_BATCH_ID', byteLength: 32 })
14-
Types.asHexString(process.env.JEST_LIGHT_BATCH_ID, { name: 'JEST_LIGHT_BATCH_ID', byteLength: 32 })
10+
Types.asString(process.env.JEST_BEE_URL, { name: 'JEST_BEE_URL' })
11+
Types.asString(process.env.JEST_BEE_SIGNER, { name: 'JEST_BEE_SIGNER' })
12+
Types.asHexString(process.env.JEST_MANAGED_BATCH_ID, { name: 'JEST_MANAGED_BATCH_ID', byteLength: 32 })
13+
Types.asHexString(process.env.JEST_EXTERNAL_BATCH_ID, { name: 'JEST_EXTERNAL_BATCH_ID', byteLength: 32 })
14+
Types.asString(process.env.JEST_WITHDRAW_ADDRESS, { name: 'JEST_WITHDRAW_ADDRESS' })
1515

1616
return {
1717
collectCoverage: true,

src/manifest/manifest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ export class Fork {
9292
return Binary.concatBytes(...data)
9393
}
9494

95-
static unmarshal(reader: Uint8ArrayReader): Fork {
95+
static unmarshal(reader: Uint8ArrayReader, addressLength: number): Fork {
9696
const type = Binary.uint8ToNumber(reader.read(1))
9797
const prefixLength = Binary.uint8ToNumber(reader.read(1))
9898
const prefix = reader.read(prefixLength)
9999
reader.read(30 - prefixLength)
100-
const selfAddress = reader.read(32)
100+
const selfAddress = reader.read(addressLength)
101101
let metadata: Record<string, string> | undefined = undefined
102102

103103
if (isType(type, TYPE_WITH_METADATA)) {
@@ -292,7 +292,7 @@ export class MantarayNode {
292292
const forkBitmap = reader.read(32)
293293
for (let i = 0; i < 256; i++) {
294294
if (Binary.getBit(forkBitmap, i, 'LE')) {
295-
const newFork = Fork.unmarshal(reader)
295+
const newFork = Fork.unmarshal(reader, targetAddressLength)
296296
node.forks.set(i, newFork)
297297
newFork.node.parent = node
298298
}

src/modules/debug/status.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import type { DebugStatus, Health, NodeInfo, Readiness } from '../../types/debug
55
import { BeeVersions, toBeeMode } from '../../types/debug'
66
import { http } from '../../utils/http'
77

8-
export const SUPPORTED_BEE_VERSION_EXACT = '2.4.0-390a402e'
8+
export const SUPPORTED_BEE_VERSION_EXACT = '2.6.0-d0aa8b93'
99
export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.split('-')[0]
10-
export const SUPPORTED_API_VERSION = '7.2.0'
10+
export const SUPPORTED_API_VERSION = '7.3.0'
1111

1212
const NODE_INFO_URL = 'node'
1313
const STATUS_URL = 'status'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { MantarayNode } from '../../src'
2+
import { makeBee } from '../utils'
3+
4+
test('decrypt a manifest that is encrypted and obfuscated', async () => {
5+
const bee = makeBee()
6+
const reference =
7+
'2874296904931ffea2ae85c7a2646756e2c475d5d5983c14c1002a510a4a3ca0b53ee9d62fd060b58cab6b47d3f26b4f3f3c614c74bd689af2bfa756d80152ca'
8+
9+
const node = await MantarayNode.unmarshal(bee, reference)
10+
await node.loadRecursively(bee)
11+
12+
const items = node.collectAndMap()
13+
expect(items['.editorconfig']).toBe(
14+
'ef7b55dd0059af17c861e4b7b81b62d32d131b510eae1f21e8b550f864305ebca4546334599af9a91052cc183216e336e9fc815ebc3f7fc8cc88004a5e81f426',
15+
)
16+
})

test/integration/stake.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test('GET stake', async () => {
88
const stake = await bee.getStake()
99

1010
if (currentBeeMode() === 'full') {
11-
expect(parseFloat(stake.toDecimalString())).toBeGreaterThan(200)
11+
expect(parseFloat(stake.toDecimalString())).toBeGreaterThan(10)
1212
} else {
1313
expect(parseFloat(stake.toDecimalString())).toBe(0)
1414
}

test/integration/stamp.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ test('GET batches', async () => {
2121
})
2222

2323
test('POST stamps', async () => {
24-
const response = await bee.createPostageBatch('580000000', 17, { waitForUsable: true })
24+
const response = await bee.createPostageBatch('1098006401', 17, { waitForUsable: true })
2525
expect(response.toHex()).toHaveLength(64)
2626

27-
await bee.topUpBatch(response, '580000000')
27+
await bee.topUpBatch(response, '1098006401')
2828

2929
await System.waitFor(
3030
async () => {

test/integration/stamper.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ test('Stamper', async () => {
66
const bee = makeBee()
77

88
const stamper = Stamper.fromBlank(
9-
Types.asString(process.env.JEST_BEE_FULL_PK),
10-
'b24b3f3ac5c7727cb9ad17b15167e75df33708f201c947f3cc6658348c2df31d',
9+
Types.asString(process.env.JEST_BEE_SIGNER),
10+
Types.asString(process.env.JEST_EXTERNAL_BATCH_ID),
1111
17,
1212
)
1313

@@ -25,8 +25,8 @@ test('Stamper', async () => {
2525
expect(state.reduce((a, b) => a + b)).toBe(1)
2626

2727
const nextStamper = Stamper.fromState(
28-
Types.asString(process.env.JEST_BEE_FULL_PK),
29-
'ae0b4d8548d17fb70672c5e7a9717de5f855d3f398a3cc2f0e445e2eecca2622',
28+
Types.asString(process.env.JEST_BEE_SIGNER),
29+
Types.asString(process.env.JEST_EXTERNAL_BATCH_ID),
3030
state,
3131
17,
3232
)

test/integration/status.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ test('GET wallet', async () => {
7171
const wallet = await bee.getWalletBalance()
7272
expect(parseFloat(wallet.bzzBalance.toDecimalString())).toBeGreaterThan(20)
7373
expect(parseFloat(wallet.bzzBalance.toDecimalString())).toBeLessThan(200)
74-
expect(parseFloat(wallet.nativeTokenBalance.toDecimalString())).toBeGreaterThan(4)
75-
expect(parseFloat(wallet.nativeTokenBalance.toDecimalString())).toBeLessThan(5)
74+
expect(parseFloat(wallet.nativeTokenBalance.toDecimalString())).toBeGreaterThan(1)
75+
expect(parseFloat(wallet.nativeTokenBalance.toDecimalString())).toBeLessThan(2)
7676
})
7777

7878
test('GET status', async () => {

test/integration/withdraw.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Dates, System } from 'cafe-utility'
1+
import { Dates, System, Types } from 'cafe-utility'
22
import { makeBee } from '../utils'
33

44
const bee = makeBee()
55

66
test('withdraw to external wallet', async () => {
77
const walletBefore = await bee.getWalletBalance()
88

9-
await bee.withdrawBZZToExternalWallet('1', process.env.JEST_WITHDRAW_ADDRESS!)
9+
await bee.withdrawBZZToExternalWallet('1', Types.asString(process.env.JEST_WITHDRAW_ADDRESS))
1010
await System.waitFor(
1111
async () => {
1212
const pendingTransactions = await bee.getAllPendingTransactions()
@@ -16,7 +16,7 @@ test('withdraw to external wallet', async () => {
1616
60,
1717
)
1818

19-
await bee.withdrawDAIToExternalWallet('1', process.env.JEST_WITHDRAW_ADDRESS!)
19+
await bee.withdrawDAIToExternalWallet('1', Types.asString(process.env.JEST_WITHDRAW_ADDRESS))
2020
await System.waitFor(
2121
async () => {
2222
const pendingTransactions = await bee.getAllPendingTransactions()

test/regression/bee-js-986.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Types } from 'cafe-utility'
12
import { mocked } from '../mocks'
23
import { batch } from '../utils'
34

@@ -32,7 +33,7 @@ test('bee-js/986 - Headers not merging properly', async () => {
3233
host: 'localhost:11633',
3334
'swarm-act': 'true',
3435
'swarm-encrypt': 'true',
35-
'swarm-postage-batch-id': 'b961413232c96eedae48947a71c99e454e51c4b5bf93a77c59f958af1229a932',
36+
'swarm-postage-batch-id': Types.asString(process.env.JEST_MANAGED_BATCH_ID),
3637
'swarm-tag': '1337',
3738
'user-agent': 'axios/0.30.0',
3839
},
@@ -49,7 +50,7 @@ test('bee-js/986 - Headers not merging properly', async () => {
4950
host: 'localhost:11633',
5051
'swarm-act': 'true',
5152
'swarm-encrypt': 'true',
52-
'swarm-postage-batch-id': 'f8b2ad296d64824a8fe51a33ff15fe8668df13a20ad3d4eea4bb97ca600029aa',
53+
'swarm-postage-batch-id': Types.asString(process.env.JEST_MANAGED_BATCH_ID),
5354
'swarm-tag': '1338',
5455
'user-agent': 'axios/0.30.0',
5556
},

0 commit comments

Comments
 (0)