Skip to content

Commit 36a4e4f

Browse files
committed
fix: fix test
1 parent 9652201 commit 36a4e4f

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

examples/ts/anda_x402/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async function main() {
7474
console.log('\n\nSettle Response:', settleJson)
7575
// Settle Response: {
7676
// success: true,
77-
// transaction: 'druyg-tyaaa-aaaaq-aactq-cai:23',
77+
// transaction: '3:druyg-tyaaa-aaaaq-aactq-cai:30',
7878
// network: 'icp-ogkpr-lyaaa-aaaap-an5fq-cai',
7979
// payer: 'jjn6g-sh75l-r3cxb-wxrkl-frqld-6p6qq-d4ato-wske5-op7s5-n566f-bqe'
8080
// }

rs/anda_cloud_cdk/src/x402.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ mod tests {
666666
// a662746f581dfd5458e209ca338118c5ddaf66d37151417bd3e91e748ba2ea499d55026561737365744a00000000020000a70101656e6f6e6365182a6576616c75656931303030303030303066736368656d65656578616374696578706972657341741b0000019a23bc21f6
667667

668668
let digest = auth.digest();
669-
let expected_hex = "152123b3911c3faed77fe0642f36332d495ab97417aeca0c7cae27ab83e517bd"; // Placeholder
669+
let expected_hex = "14a9c138b21790526a43aa8ca2bb1f0c3618eda2fe02347002cac8f11b255cfc"; // Placeholder
670670
assert_eq!(hex::encode(digest), expected_hex);
671671
}
672672
}

ts/anda_x402/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ldclabs/anda_x402",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"type": "module",
55
"description": "The Typescript version of the client SDK for the Anda x402.",
66
"license": "MIT",

ts/anda_x402/src/x402.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// (c) 2023-present, LDC Labs. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
import { assert, describe, it } from 'vitest'
5+
import { deterministicEncode } from '@ldclabs/ic-auth'
6+
import { sha3_256 } from '@noble/hashes/sha3'
7+
import type { IcpPayloadAuthorization } from './types.js'
8+
9+
describe('IcpPayload', () => {
10+
it('IcpPayloadAuthorization digest', async () => {
11+
const auth: IcpPayloadAuthorization = {
12+
scheme: 'exact',
13+
asset: 'druyg-tyaaa-aaaaq-aactq-cai',
14+
to: '77ibd-jp5kr-moeco-kgoar-rro5v-5tng4-krif5-5h2i6-osf2f-2sjtv-kqe',
15+
value: '100000000',
16+
expiresAt: 1761536123382,
17+
nonce: 42
18+
}
19+
const digest = sha3_256(deterministicEncode(auth))
20+
assert.equal(
21+
Buffer.from(digest).toString('hex'),
22+
'14a9c138b21790526a43aa8ca2bb1f0c3618eda2fe02347002cac8f11b255cfc'
23+
)
24+
})
25+
})

ts/anda_x402/src/x402.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ export class X402Canister {
7474

7575
async signPayload(data: IcpPayloadAuthorization): Promise<string> {
7676
const sig = await signCborMessage(this.#identity, data)
77-
console.log('Signature:', Buffer.from(sig.h!).toString('hex'))
78-
console.log('Signed data:', data)
7977
delete sig.h
8078
return bytesToBase64Url(deterministicEncode(sig))
8179
}

0 commit comments

Comments
 (0)