goscript 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/cmd/go_js_wasm_exec/main.go +1 -1
- package/cmd/go_js_wasm_exec/main_test.go +1 -1
- package/cmd/goscript/cmd-compile.go +9 -1
- package/cmd/goscript/cmd-test.go +1 -1
- package/cmd/goscript/cmd_compile_test.go +44 -0
- package/cmd/goscript/deps.go +1 -1
- package/cmd/goscript-wasm/main.go +2 -2
- package/compiler/compile-request.go +19 -0
- package/compiler/compile_bench_test.go +121 -0
- package/compiler/compliance_test.go +17 -1
- package/compiler/config.go +2 -0
- package/compiler/gotest/result.go +1 -1
- package/compiler/gotest/runner.go +2 -2
- package/compiler/gotest/runner_test.go +4 -7
- package/compiler/index.test.ts +28 -0
- package/compiler/index.ts +32 -16
- package/compiler/lowering.go +1236 -143
- package/compiler/lowering_bench_test.go +4 -0
- package/compiler/override-facts.go +1 -1
- package/compiler/override-registry_test.go +125 -0
- package/compiler/package-graph.go +92 -0
- package/compiler/package-graph_test.go +113 -0
- package/compiler/runtime-contract.go +1 -1
- package/compiler/semantic-model.go +32 -0
- package/compiler/skeleton_test.go +284 -11
- package/compiler/wasm/compile.go +1 -1
- package/compiler/wasm/compile_test.go +1 -1
- package/dist/compiler/index.d.ts +4 -0
- package/dist/compiler/index.js +26 -15
- package/dist/compiler/index.js.map +1 -1
- package/dist/gs/compress/gzip/index.d.ts +41 -0
- package/dist/gs/compress/gzip/index.js +235 -0
- package/dist/gs/compress/gzip/index.js.map +1 -0
- package/dist/gs/database/sql/driver/index.d.ts +165 -0
- package/dist/gs/database/sql/driver/index.js +432 -0
- package/dist/gs/database/sql/driver/index.js.map +1 -0
- package/dist/gs/encoding/binary/index.d.ts +71 -0
- package/dist/gs/encoding/binary/index.js +778 -0
- package/dist/gs/encoding/binary/index.js.map +1 -0
- package/dist/gs/fmt/fmt.js +156 -57
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/github.com/klauspost/cpuid/v2/index.d.ts +11 -0
- package/dist/gs/github.com/klauspost/cpuid/v2/index.js +28 -0
- package/dist/gs/github.com/klauspost/cpuid/v2/index.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/errors.d.ts +0 -2
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/index.d.ts +2 -1
- package/dist/gs/github.com/pkg/errors/index.js +1 -1
- package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/stack.d.ts +8 -19
- package/dist/gs/github.com/pkg/errors/stack.js +26 -61
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
- package/dist/gs/golang.org/x/crypto/cryptobyte/asn1/index.d.ts +19 -0
- package/dist/gs/golang.org/x/crypto/cryptobyte/asn1/index.js +25 -0
- package/dist/gs/golang.org/x/crypto/cryptobyte/asn1/index.js.map +1 -0
- package/dist/gs/golang.org/x/crypto/cryptobyte/index.d.ts +104 -0
- package/dist/gs/golang.org/x/crypto/cryptobyte/index.js +1107 -0
- package/dist/gs/golang.org/x/crypto/cryptobyte/index.js.map +1 -0
- package/dist/gs/golang.org/x/crypto/internal/alias/index.d.ts +3 -0
- package/dist/gs/golang.org/x/crypto/internal/alias/index.js +39 -0
- package/dist/gs/golang.org/x/crypto/internal/alias/index.js.map +1 -0
- package/dist/gs/io/fs/glob.js +1 -1
- package/dist/gs/io/fs/glob.js.map +1 -1
- package/dist/gs/io/fs/readlink.d.ts +1 -1
- package/dist/gs/io/fs/readlink.js +2 -2
- package/dist/gs/io/fs/readlink.js.map +1 -1
- package/dist/gs/io/fs/stat.d.ts +4 -2
- package/dist/gs/io/fs/stat.js +12 -73
- package/dist/gs/io/fs/stat.js.map +1 -1
- package/dist/gs/io/fs/sub.d.ts +2 -2
- package/dist/gs/io/fs/sub.js +7 -7
- package/dist/gs/io/fs/sub.js.map +1 -1
- package/dist/gs/io/fs/walk.js +1 -1
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/net/http/index.d.ts +18 -14
- package/dist/gs/net/http/index.js +44 -23
- package/dist/gs/net/http/index.js.map +1 -1
- package/dist/gs/net/http/pprof/index.d.ts +5 -5
- package/dist/gs/net/http/pprof/index.js +21 -21
- package/dist/gs/net/http/pprof/index.js.map +1 -1
- package/dist/gs/runtime/runtime.d.ts +6 -1
- package/dist/gs/runtime/runtime.js +15 -8
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/runtime/trace/index.d.ts +8 -5
- package/dist/gs/runtime/trace/index.js +324 -23
- package/dist/gs/runtime/trace/index.js.map +1 -1
- package/dist/gs/slices/slices.d.ts +2 -1
- package/dist/gs/slices/slices.js +9 -3
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sort/search.gs.d.ts +3 -1
- package/dist/gs/sort/search.gs.js +18 -53
- package/dist/gs/sort/search.gs.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +1 -1
- package/dist/gs/sync/sync.js +3 -0
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/time/time.d.ts +22 -29
- package/dist/gs/time/time.js +111 -32
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unsafe/unsafe.d.ts +3 -2
- package/dist/gs/unsafe/unsafe.js.map +1 -1
- package/go.mod +7 -5
- package/go.sum +12 -26
- package/gs/builtin/runtime-contract.test.ts +25 -0
- package/gs/compress/gzip/index.test.ts +86 -0
- package/gs/compress/gzip/index.ts +297 -0
- package/gs/compress/gzip/meta.json +6 -0
- package/gs/compress/gzip/parity.json +45 -0
- package/gs/database/sql/driver/index.test.ts +88 -0
- package/gs/database/sql/driver/index.ts +675 -0
- package/gs/database/sql/driver/meta.json +3 -0
- package/gs/database/sql/driver/parity.json +144 -0
- package/gs/embed/index.test.ts +1 -1
- package/gs/encoding/binary/index.test.ts +239 -0
- package/gs/encoding/binary/index.ts +999 -0
- package/gs/encoding/binary/meta.json +9 -0
- package/gs/encoding/binary/parity.json +72 -0
- package/gs/fmt/fmt.test.ts +28 -0
- package/gs/fmt/fmt.ts +198 -61
- package/gs/fmt/meta.json +2 -1
- package/gs/github.com/klauspost/cpuid/v2/index.ts +38 -0
- package/gs/github.com/klauspost/cpuid/v2/meta.json +3 -0
- package/gs/github.com/pkg/errors/errors.ts +1 -2
- package/gs/github.com/pkg/errors/index.ts +2 -1
- package/gs/github.com/pkg/errors/stack.ts +34 -62
- package/gs/golang.org/x/crypto/cryptobyte/asn1/index.test.ts +19 -0
- package/gs/golang.org/x/crypto/cryptobyte/asn1/index.ts +29 -0
- package/gs/golang.org/x/crypto/cryptobyte/index.test.ts +255 -0
- package/gs/golang.org/x/crypto/cryptobyte/index.ts +1441 -0
- package/gs/golang.org/x/crypto/cryptobyte/meta.json +3 -0
- package/gs/golang.org/x/crypto/internal/alias/index.test.ts +40 -0
- package/gs/golang.org/x/crypto/internal/alias/index.ts +40 -0
- package/gs/io/fs/glob.ts +1 -1
- package/gs/io/fs/meta.json +3 -0
- package/gs/io/fs/readlink.test.ts +2 -2
- package/gs/io/fs/readlink.ts +5 -2
- package/gs/io/fs/stat.test.ts +79 -0
- package/gs/io/fs/stat.ts +24 -10
- package/gs/io/fs/sub.test.ts +93 -0
- package/gs/io/fs/sub.ts +9 -9
- package/gs/io/fs/walk.ts +1 -1
- package/gs/net/http/index.test.ts +207 -2
- package/gs/net/http/index.ts +68 -37
- package/gs/net/http/meta.json +3 -1
- package/gs/net/http/pprof/index.test.ts +4 -4
- package/gs/net/http/pprof/index.ts +30 -27
- package/gs/runtime/runtime.test.ts +16 -0
- package/gs/runtime/runtime.ts +17 -9
- package/gs/runtime/trace/index.test.ts +113 -14
- package/gs/runtime/trace/index.ts +384 -34
- package/gs/runtime/trace/meta.json +1 -0
- package/gs/slices/slices.test.ts +24 -1
- package/gs/slices/slices.ts +14 -4
- package/gs/sort/meta.json +1 -0
- package/gs/sort/search.gs.ts +20 -5
- package/gs/sync/sync.ts +4 -1
- package/gs/time/time.test.ts +79 -2
- package/gs/time/time.ts +133 -33
- package/gs/unsafe/unsafe.ts +4 -2
- package/package.json +2 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BOOLEAN,
|
|
5
|
+
INTEGER,
|
|
6
|
+
SEQUENCE,
|
|
7
|
+
Tag_Constructed,
|
|
8
|
+
Tag_ContextSpecific,
|
|
9
|
+
} from './index.js'
|
|
10
|
+
|
|
11
|
+
describe('cryptobyte/asn1 override', () => {
|
|
12
|
+
it('exports tag constants and class helpers', () => {
|
|
13
|
+
expect(BOOLEAN).toBe(1)
|
|
14
|
+
expect(INTEGER).toBe(2)
|
|
15
|
+
expect(SEQUENCE).toBe(0x30)
|
|
16
|
+
expect(Tag_Constructed(16)).toBe(0x30)
|
|
17
|
+
expect(Tag_ContextSpecific(3)).toBe(0x83)
|
|
18
|
+
})
|
|
19
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type Tag = number
|
|
2
|
+
|
|
3
|
+
const classConstructed = 0x20
|
|
4
|
+
const classContextSpecific = 0x80
|
|
5
|
+
|
|
6
|
+
export function Tag_Constructed(t: Tag): Tag {
|
|
7
|
+
return (t | classConstructed) & 0xff
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function Tag_ContextSpecific(t: Tag): Tag {
|
|
11
|
+
return (t | classContextSpecific) & 0xff
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const BOOLEAN: Tag = 1
|
|
15
|
+
export const INTEGER: Tag = 2
|
|
16
|
+
export const BIT_STRING: Tag = 3
|
|
17
|
+
export const OCTET_STRING: Tag = 4
|
|
18
|
+
export const NULL: Tag = 5
|
|
19
|
+
export const OBJECT_IDENTIFIER: Tag = 6
|
|
20
|
+
export const ENUM: Tag = 10
|
|
21
|
+
export const UTF8String: Tag = 12
|
|
22
|
+
export const SEQUENCE: Tag = 16 | classConstructed
|
|
23
|
+
export const SET: Tag = 17 | classConstructed
|
|
24
|
+
export const PrintableString: Tag = 19
|
|
25
|
+
export const T61String: Tag = 20
|
|
26
|
+
export const IA5String: Tag = 22
|
|
27
|
+
export const UTCTime: Tag = 23
|
|
28
|
+
export const GeneralizedTime: Tag = 24
|
|
29
|
+
export const GeneralString: Tag = 27
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
4
|
+
import * as asn1 from '@goscript/golang.org/x/crypto/cryptobyte/asn1/index.js'
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
BuildError,
|
|
8
|
+
NewBuilder,
|
|
9
|
+
NewFixedBuilder,
|
|
10
|
+
String_CopyBytes,
|
|
11
|
+
String_Empty,
|
|
12
|
+
String_ReadASN1,
|
|
13
|
+
String_ReadASN1Boolean,
|
|
14
|
+
String_ReadASN1Integer,
|
|
15
|
+
String_ReadBytes,
|
|
16
|
+
String_ReadOptionalASN1,
|
|
17
|
+
String_ReadOptionalASN1Integer,
|
|
18
|
+
String_ReadUint16,
|
|
19
|
+
String_ReadUint24,
|
|
20
|
+
String_ReadUint32,
|
|
21
|
+
String_ReadUint48,
|
|
22
|
+
String_ReadUint64,
|
|
23
|
+
String_ReadUint8,
|
|
24
|
+
type String,
|
|
25
|
+
} from './index.js'
|
|
26
|
+
|
|
27
|
+
class FakeBigInt {
|
|
28
|
+
public value: bigint
|
|
29
|
+
|
|
30
|
+
constructor(value = 0n) {
|
|
31
|
+
this.value = value
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public SetBytes(bytes: $.Bytes): FakeBigInt {
|
|
35
|
+
let value = 0n
|
|
36
|
+
for (const b of Array.from($.bytesToUint8Array(bytes))) {
|
|
37
|
+
value = (value << 8n) | BigInt(b)
|
|
38
|
+
}
|
|
39
|
+
this.value = value
|
|
40
|
+
return this
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public Bytes(): $.Bytes {
|
|
44
|
+
if (this.value === 0n) {
|
|
45
|
+
return new Uint8Array(0)
|
|
46
|
+
}
|
|
47
|
+
let value = this.value < 0n ? -this.value : this.value
|
|
48
|
+
const out: number[] = []
|
|
49
|
+
while (value > 0n) {
|
|
50
|
+
out.unshift(Number(value & 0xffn))
|
|
51
|
+
value >>= 8n
|
|
52
|
+
}
|
|
53
|
+
return new Uint8Array(out)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public Sign(): number {
|
|
57
|
+
if (this.value < 0n) {
|
|
58
|
+
return -1
|
|
59
|
+
}
|
|
60
|
+
if (this.value > 0n) {
|
|
61
|
+
return 1
|
|
62
|
+
}
|
|
63
|
+
return 0
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public Neg(value: FakeBigInt): FakeBigInt {
|
|
67
|
+
this.value = -value.value
|
|
68
|
+
return this
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public String(): string {
|
|
72
|
+
return this.value.toString()
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function bytes(value: $.Bytes): number[] {
|
|
77
|
+
return Array.from($.bytesToUint8Array(value))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function typedRef<T>(value: T, typeName: string): $.VarRef<T> {
|
|
81
|
+
const ref = $.varRef(value) as $.VarRef<T> & { __goType?: string }
|
|
82
|
+
ref.__goType = typeName
|
|
83
|
+
return ref
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
describe('cryptobyte override Builder', () => {
|
|
87
|
+
it('writes fixed-width integers and raw bytes', () => {
|
|
88
|
+
const b = NewBuilder()
|
|
89
|
+
b.AddUint8(0x01)
|
|
90
|
+
b.AddUint16(0x0203)
|
|
91
|
+
b.AddUint24(0x040506)
|
|
92
|
+
b.AddUint32(0x0708090a)
|
|
93
|
+
b.AddUint48(0x0b0c0d0e0f10)
|
|
94
|
+
b.AddUint64($.uint(0x1112131415161718n, 64))
|
|
95
|
+
b.AddBytes(new Uint8Array([0x19, 0x1a]))
|
|
96
|
+
|
|
97
|
+
const [out, err] = b.Bytes()
|
|
98
|
+
expect(err).toBeNull()
|
|
99
|
+
expect(bytes(out)).toEqual([
|
|
100
|
+
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
|
|
101
|
+
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
|
|
102
|
+
0x17, 0x18, 0x19, 0x1a,
|
|
103
|
+
])
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('writes ASN.1 length prefixes and reports fixed builder errors', () => {
|
|
107
|
+
const b = NewBuilder()
|
|
108
|
+
b.AddASN1(asn1.SEQUENCE, (child) => {
|
|
109
|
+
child!.AddASN1Int64(1)
|
|
110
|
+
child!.AddASN1Uint64(300)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const [out, err] = b.Bytes()
|
|
114
|
+
expect(err).toBeNull()
|
|
115
|
+
expect(bytes(out)).toEqual([
|
|
116
|
+
0x30, 0x07, 0x02, 0x01, 0x01, 0x02, 0x02, 0x01, 0x2c,
|
|
117
|
+
])
|
|
118
|
+
|
|
119
|
+
const fixed = NewFixedBuilder($.makeSlice<number>(0, 2, 'byte'))
|
|
120
|
+
fixed.AddBytes(new Uint8Array([1, 2, 3]))
|
|
121
|
+
const [, fixedErr] = fixed.Bytes()
|
|
122
|
+
expect(fixedErr?.Error()).toContain('fixed-size buffer')
|
|
123
|
+
|
|
124
|
+
const panicBuilder = NewBuilder()
|
|
125
|
+
panicBuilder.SetError($.newError('boom'))
|
|
126
|
+
expect(() => panicBuilder.BytesOrPanic()).toThrow()
|
|
127
|
+
try {
|
|
128
|
+
panicBuilder.BytesOrPanic()
|
|
129
|
+
} catch (err) {
|
|
130
|
+
expect($.panicValue(err)).toBeInstanceOf(BuildError)
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
describe('cryptobyte override String', () => {
|
|
136
|
+
it('reads fixed-width integers and bytes', () => {
|
|
137
|
+
const input = $.varRef<String>(
|
|
138
|
+
new Uint8Array([
|
|
139
|
+
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
|
|
140
|
+
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0xaa, 0xbb,
|
|
141
|
+
]),
|
|
142
|
+
)
|
|
143
|
+
const u8 = $.varRef(0)
|
|
144
|
+
const u16 = $.varRef(0)
|
|
145
|
+
const u24 = $.varRef(0)
|
|
146
|
+
const u32 = $.varRef(0)
|
|
147
|
+
const u48 = $.varRef(0)
|
|
148
|
+
const u64 = $.varRef(0)
|
|
149
|
+
const tail = $.varRef<$.Bytes>(new Uint8Array(0))
|
|
150
|
+
|
|
151
|
+
expect(String_ReadUint8(input, u8)).toBe(true)
|
|
152
|
+
expect(String_ReadUint16(input, u16)).toBe(true)
|
|
153
|
+
expect(String_ReadUint24(input, u24)).toBe(true)
|
|
154
|
+
expect(String_ReadUint32(input, u32)).toBe(true)
|
|
155
|
+
expect(String_ReadUint48(input, u48)).toBe(true)
|
|
156
|
+
expect(String_ReadBytes(input, tail, 2)).toBe(true)
|
|
157
|
+
|
|
158
|
+
expect(u8.value).toBe(0x01)
|
|
159
|
+
expect(u16.value).toBe(0x0203)
|
|
160
|
+
expect(u24.value).toBe(0x040506)
|
|
161
|
+
expect(u32.value).toBe(0x0708090a)
|
|
162
|
+
expect(u48.value).toBe(0x0b0c0d0e0f10)
|
|
163
|
+
expect(bytes(tail.value)).toEqual([0xaa, 0xbb])
|
|
164
|
+
|
|
165
|
+
const wide = $.varRef<String>(
|
|
166
|
+
new Uint8Array([0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18]),
|
|
167
|
+
)
|
|
168
|
+
expect(String_ReadUint64(wide, u64)).toBe(true)
|
|
169
|
+
expect(u64.value).toBe($.uint(0x1112131415161718n, 64))
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
it('reads ASN.1 integers, booleans, optional values, and round trips sequences', () => {
|
|
173
|
+
const b = NewBuilder()
|
|
174
|
+
b.AddASN1(asn1.SEQUENCE, (seq) => {
|
|
175
|
+
seq!.AddASN1Int64(42)
|
|
176
|
+
seq!.AddASN1Uint64(65537)
|
|
177
|
+
seq!.AddASN1Boolean(true)
|
|
178
|
+
})
|
|
179
|
+
const [encoded] = b.Bytes()
|
|
180
|
+
const input = $.varRef<String>(encoded)
|
|
181
|
+
const seq = $.varRef<String>(new Uint8Array(0))
|
|
182
|
+
|
|
183
|
+
expect(String_ReadASN1(input, seq, asn1.SEQUENCE)).toBe(true)
|
|
184
|
+
const signed = typedRef(0, '*int64')
|
|
185
|
+
const unsigned = typedRef(0, '*uint64')
|
|
186
|
+
const flag = $.varRef(false)
|
|
187
|
+
|
|
188
|
+
expect(String_ReadASN1Integer(seq, signed)).toBe(true)
|
|
189
|
+
expect(String_ReadASN1Integer(seq, unsigned)).toBe(true)
|
|
190
|
+
expect(String_ReadASN1Boolean(seq, flag)).toBe(true)
|
|
191
|
+
expect(signed.value).toBe(42)
|
|
192
|
+
expect(unsigned.value).toBe(65537)
|
|
193
|
+
expect(flag.value).toBe(true)
|
|
194
|
+
expect(String_Empty(seq.value)).toBe(true)
|
|
195
|
+
|
|
196
|
+
const absent = $.varRef<String>(new Uint8Array(0))
|
|
197
|
+
const optional = $.varRef<String>(new Uint8Array([0]))
|
|
198
|
+
expect(
|
|
199
|
+
String_ReadOptionalASN1(absent, optional, asn1.OCTET_STRING, new Uint8Array([9])),
|
|
200
|
+
).toBe(true)
|
|
201
|
+
expect(bytes(optional.value)).toEqual([9])
|
|
202
|
+
|
|
203
|
+
const defaultBig = typedRef(new FakeBigInt(), '*big.Int')
|
|
204
|
+
expect(
|
|
205
|
+
String_ReadOptionalASN1Integer(
|
|
206
|
+
$.varRef<String>(new Uint8Array(0)),
|
|
207
|
+
defaultBig,
|
|
208
|
+
asn1.INTEGER,
|
|
209
|
+
new FakeBigInt(99n),
|
|
210
|
+
),
|
|
211
|
+
).toBe(true)
|
|
212
|
+
expect(defaultBig.value.value).toBe(99n)
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('round trips ECDSA-style integer pairs and big.Int values', () => {
|
|
216
|
+
const r = new FakeBigInt(0x0102030405060708n)
|
|
217
|
+
const s = new FakeBigInt(0x80n)
|
|
218
|
+
const b = NewBuilder()
|
|
219
|
+
b.AddASN1(asn1.SEQUENCE, (seq) => {
|
|
220
|
+
seq!.AddASN1BigInt(r)
|
|
221
|
+
seq!.AddASN1BigInt(s)
|
|
222
|
+
})
|
|
223
|
+
const [encoded, err] = b.Bytes()
|
|
224
|
+
expect(err).toBeNull()
|
|
225
|
+
|
|
226
|
+
const input = $.varRef<String>(encoded)
|
|
227
|
+
const seq = $.varRef<String>(new Uint8Array(0))
|
|
228
|
+
const rOut = typedRef(new FakeBigInt(), '*big.Int')
|
|
229
|
+
const sOut = typedRef(new FakeBigInt(), '*big.Int')
|
|
230
|
+
|
|
231
|
+
expect(String_ReadASN1(input, seq, asn1.SEQUENCE)).toBe(true)
|
|
232
|
+
expect(String_ReadASN1Integer(seq, rOut)).toBe(true)
|
|
233
|
+
expect(String_ReadASN1Integer(seq, sOut)).toBe(true)
|
|
234
|
+
expect(rOut.value.value).toBe(r.value)
|
|
235
|
+
expect(sOut.value.value).toBe(s.value)
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('marshals and unmarshals a fixed 32-byte string payload', () => {
|
|
239
|
+
const payload = new Uint8Array(Array.from({ length: 32 }, (_, i) => i + 1))
|
|
240
|
+
const b = NewBuilder()
|
|
241
|
+
b.AddBytes(payload)
|
|
242
|
+
const [encoded, err] = b.Bytes()
|
|
243
|
+
expect(err).toBeNull()
|
|
244
|
+
|
|
245
|
+
const input = $.varRef<String>(encoded)
|
|
246
|
+
const out = $.varRef<$.Bytes>(new Uint8Array(0))
|
|
247
|
+
const copied = new Uint8Array(32)
|
|
248
|
+
|
|
249
|
+
expect(String_ReadBytes(input, out, 32)).toBe(true)
|
|
250
|
+
expect(bytes(out.value)).toEqual(bytes(payload))
|
|
251
|
+
input.value = encoded
|
|
252
|
+
expect(String_CopyBytes(input, copied)).toBe(true)
|
|
253
|
+
expect(bytes(copied)).toEqual(bytes(payload))
|
|
254
|
+
})
|
|
255
|
+
})
|