@alephium/web3 0.36.1 → 0.38.0

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.
Files changed (95) hide show
  1. package/dist/alephium-web3.min.js +1 -1
  2. package/dist/alephium-web3.min.js.map +1 -1
  3. package/dist/src/api/api-alephium.d.ts +6 -1
  4. package/dist/src/api/api-alephium.js +1 -1
  5. package/dist/src/api/types.d.ts +1 -1
  6. package/dist/src/codec/array-codec.d.ts +17 -0
  7. package/dist/src/codec/array-codec.js +59 -0
  8. package/dist/src/codec/asset-output-codec.d.ts +27 -0
  9. package/dist/src/codec/asset-output-codec.js +135 -0
  10. package/dist/src/codec/bigint-codec.d.ts +5 -0
  11. package/dist/src/codec/bigint-codec.js +86 -0
  12. package/dist/src/codec/bytestring-codec.d.ts +16 -0
  13. package/dist/src/codec/bytestring-codec.js +50 -0
  14. package/dist/src/codec/codec.d.ts +8 -0
  15. package/dist/src/codec/codec.js +9 -0
  16. package/dist/src/codec/compact-int-codec.d.ts +51 -0
  17. package/dist/src/codec/compact-int-codec.js +300 -0
  18. package/dist/src/codec/contract-codec.d.ts +23 -0
  19. package/dist/src/codec/contract-codec.js +81 -0
  20. package/dist/src/codec/contract-output-codec.d.ts +21 -0
  21. package/dist/src/codec/contract-output-codec.js +82 -0
  22. package/dist/src/codec/contract-output-ref-codec.d.ts +15 -0
  23. package/dist/src/codec/contract-output-ref-codec.js +38 -0
  24. package/dist/src/codec/either-codec.d.ts +17 -0
  25. package/dist/src/codec/either-codec.js +67 -0
  26. package/dist/src/codec/hash.d.ts +4 -0
  27. package/dist/src/codec/hash.js +23 -0
  28. package/dist/src/codec/index.d.ts +23 -0
  29. package/dist/src/codec/index.js +69 -0
  30. package/dist/src/codec/input-codec.d.ts +22 -0
  31. package/dist/src/codec/input-codec.js +71 -0
  32. package/dist/src/codec/instr-codec.d.ts +230 -0
  33. package/dist/src/codec/instr-codec.js +471 -0
  34. package/dist/src/codec/lockup-script-codec.d.ts +28 -0
  35. package/dist/src/codec/lockup-script-codec.js +80 -0
  36. package/dist/src/codec/long-codec.d.ts +9 -0
  37. package/dist/src/codec/long-codec.js +56 -0
  38. package/dist/src/codec/method-codec.d.ts +31 -0
  39. package/dist/src/codec/method-codec.js +78 -0
  40. package/dist/src/codec/option-codec.d.ts +15 -0
  41. package/dist/src/codec/option-codec.js +55 -0
  42. package/dist/src/codec/output-codec.d.ts +7 -0
  43. package/dist/src/codec/output-codec.js +26 -0
  44. package/dist/src/codec/script-codec.d.ts +16 -0
  45. package/dist/src/codec/script-codec.js +41 -0
  46. package/dist/src/codec/signature-codec.d.ts +14 -0
  47. package/dist/src/codec/signature-codec.js +19 -0
  48. package/dist/src/codec/signed-int-codec.d.ts +9 -0
  49. package/dist/src/codec/signed-int-codec.js +39 -0
  50. package/dist/src/codec/token-codec.d.ts +16 -0
  51. package/dist/src/codec/token-codec.js +46 -0
  52. package/dist/src/codec/transaction-codec.d.ts +27 -0
  53. package/dist/src/codec/transaction-codec.js +128 -0
  54. package/dist/src/codec/unlock-script-codec.d.ts +40 -0
  55. package/dist/src/codec/unlock-script-codec.js +170 -0
  56. package/dist/src/codec/unsigned-tx-codec.d.ts +30 -0
  57. package/dist/src/codec/unsigned-tx-codec.js +103 -0
  58. package/dist/src/contract/contract.d.ts +14 -8
  59. package/dist/src/contract/contract.js +205 -22
  60. package/dist/src/contract/ralph.d.ts +16 -0
  61. package/dist/src/contract/ralph.js +127 -1
  62. package/dist/src/index.d.ts +1 -0
  63. package/dist/src/index.js +2 -1
  64. package/package.json +5 -4
  65. package/src/api/api-alephium.ts +7 -1
  66. package/src/api/types.ts +1 -1
  67. package/src/codec/array-codec.ts +63 -0
  68. package/src/codec/asset-output-codec.ts +149 -0
  69. package/src/codec/bigint-codec.ts +92 -0
  70. package/src/codec/bytestring-codec.ts +56 -0
  71. package/src/codec/codec.ts +31 -0
  72. package/src/codec/compact-int-codec.ts +316 -0
  73. package/src/codec/contract-codec.ts +95 -0
  74. package/src/codec/contract-output-codec.ts +95 -0
  75. package/src/codec/contract-output-ref-codec.ts +42 -0
  76. package/src/codec/either-codec.ts +74 -0
  77. package/src/codec/hash.ts +35 -0
  78. package/src/codec/index.ts +41 -0
  79. package/src/codec/input-codec.ts +81 -0
  80. package/src/codec/instr-codec.ts +479 -0
  81. package/src/codec/lockup-script-codec.ts +99 -0
  82. package/src/codec/long-codec.ts +59 -0
  83. package/src/codec/method-codec.ts +97 -0
  84. package/src/codec/option-codec.ts +60 -0
  85. package/src/codec/output-codec.ts +26 -0
  86. package/src/codec/script-codec.ts +45 -0
  87. package/src/codec/signature-codec.ts +40 -0
  88. package/src/codec/signed-int-codec.ts +37 -0
  89. package/src/codec/token-codec.ts +51 -0
  90. package/src/codec/transaction-codec.ts +147 -0
  91. package/src/codec/unlock-script-codec.ts +194 -0
  92. package/src/codec/unsigned-tx-codec.ts +124 -0
  93. package/src/contract/contract.ts +299 -23
  94. package/src/contract/ralph.ts +140 -2
  95. package/src/index.ts +1 -1
@@ -0,0 +1,95 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ import { Buffer } from 'buffer/'
20
+ import { Parser } from 'binary-parser'
21
+ import { ArrayCodec, DecodedArray } from './array-codec'
22
+ import { Codec } from './codec'
23
+ import { compactSignedIntCodec, compactUnsignedIntCodec, DecodedCompactInt } from './compact-int-codec'
24
+ import { Method, MethodCodec, methodCodec } from './method-codec'
25
+
26
+ const compactSignedIntsCodec = new ArrayCodec(compactSignedIntCodec)
27
+
28
+ export interface HalfDecodedContract {
29
+ fieldLength: DecodedCompactInt
30
+ methodIndexes: DecodedArray<DecodedCompactInt>
31
+ methods: Buffer
32
+ }
33
+
34
+ export interface Contract {
35
+ fieldLength: number
36
+ methods: Method[]
37
+ }
38
+
39
+ export function toHalfDecoded(contract: Contract): HalfDecodedContract {
40
+ const fieldLength = compactSignedIntCodec.fromI32(contract.fieldLength)
41
+ const methods = contract.methods.map((m) => methodCodec.encode(MethodCodec.fromMethod(m)))
42
+ let count = 0
43
+ const methodIndexes = Array.from(Array(methods.length).keys()).map((index) => {
44
+ count += methods[`${index}`].length
45
+ return count
46
+ })
47
+ return {
48
+ fieldLength,
49
+ methodIndexes: {
50
+ length: compactSignedIntCodec.fromI32(methodIndexes.length),
51
+ value: methodIndexes.map((value) => compactSignedIntCodec.fromI32(value))
52
+ },
53
+ methods: methods.reduce((acc, buffer) => Buffer.concat([acc, buffer]))
54
+ }
55
+ }
56
+
57
+ export class ContractCodec implements Codec<HalfDecodedContract> {
58
+ parser = Parser.start()
59
+ .nest('fieldLength', {
60
+ type: compactSignedIntCodec.parser
61
+ })
62
+ .nest('methodIndexes', {
63
+ type: compactSignedIntsCodec.parser
64
+ })
65
+ .buffer('methods', { readUntil: 'eof' })
66
+
67
+ encode(input: HalfDecodedContract): Buffer {
68
+ return Buffer.from([
69
+ ...compactSignedIntCodec.encode(input.fieldLength),
70
+ ...compactSignedIntsCodec.encode(input.methodIndexes.value),
71
+ ...input.methods
72
+ ])
73
+ }
74
+
75
+ decode(input: Buffer): HalfDecodedContract {
76
+ return this.parser.parse(input)
77
+ }
78
+
79
+ decodeContract(input: Buffer): Contract {
80
+ const halfDecoded = this.decode(input)
81
+ const fieldLength = compactUnsignedIntCodec.toU32(halfDecoded.fieldLength)
82
+ const methodIndexes = halfDecoded.methodIndexes.value.map((v) => compactUnsignedIntCodec.toU32(v))
83
+ const methods: Method[] = []
84
+ for (let i = 0, start = 0; i < methodIndexes.length; i++) {
85
+ const end = methodIndexes[i]
86
+ const method = MethodCodec.toMethod(methodCodec.decode(halfDecoded.methods.slice(start, end)))
87
+ methods.push(method)
88
+ start = end
89
+ }
90
+
91
+ return { fieldLength, methods }
92
+ }
93
+ }
94
+
95
+ export const contractCodec = new ContractCodec()
@@ -0,0 +1,95 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ import { Buffer } from 'buffer/'
19
+ import { Parser } from 'binary-parser'
20
+ import { DecodedArray } from './array-codec'
21
+ import { DecodedCompactInt, compactUnsignedIntCodec } from './compact-int-codec'
22
+ import { P2C } from './lockup-script-codec'
23
+ import { Codec } from './codec'
24
+ import { Token, tokensCodec } from './token-codec'
25
+ import { ContractOutput as ApiContractOutput } from '../api/api-alephium'
26
+ import { blakeHash, createHint } from './hash'
27
+ import { binToHex, bs58 } from '..'
28
+ import { signedIntCodec } from './signed-int-codec'
29
+ import { lockupScriptCodec } from './lockup-script-codec'
30
+
31
+ export interface ContractOutput {
32
+ amount: DecodedCompactInt
33
+ lockupScript: P2C
34
+ tokens: DecodedArray<Token>
35
+ }
36
+
37
+ export class ContractOutputCodec implements Codec<ContractOutput> {
38
+ parser = Parser.start()
39
+ .nest('amount', {
40
+ type: compactUnsignedIntCodec.parser
41
+ })
42
+ .nest('lockupScript', {
43
+ type: Parser.start().buffer('contractId', { length: 32 })
44
+ })
45
+ .nest('tokens', {
46
+ type: tokensCodec.parser
47
+ })
48
+
49
+ encode(input: ContractOutput): Buffer {
50
+ const amount = Buffer.from(compactUnsignedIntCodec.encode(input.amount))
51
+ const lockupScript = input.lockupScript.contractId
52
+ const tokens = Buffer.from(tokensCodec.encode(input.tokens.value))
53
+
54
+ return Buffer.concat([amount, lockupScript, tokens])
55
+ }
56
+
57
+ decode(input: Buffer): ContractOutput {
58
+ return this.parser.parse(input)
59
+ }
60
+
61
+ static convertToApiContractOutput(txIdBytes: Uint8Array, output: ContractOutput, index: number): ApiContractOutput {
62
+ const hint = createHint(output.lockupScript.contractId)
63
+ const key = binToHex(blakeHash(Buffer.concat([txIdBytes, signedIntCodec.encode(index)])))
64
+ const attoAlphAmount = compactUnsignedIntCodec.toU256(output.amount).toString()
65
+ const address = bs58.encode(Buffer.concat([Buffer.from([0x03]), output.lockupScript.contractId]))
66
+ const tokens = output.tokens.value.map((token) => {
67
+ return {
68
+ id: token.tokenId.toString('hex'),
69
+ amount: compactUnsignedIntCodec.toU256(token.amount).toString()
70
+ }
71
+ })
72
+ return { hint, key, attoAlphAmount, address, tokens, type: 'ContractOutput' }
73
+ }
74
+
75
+ static convertToOutput(apiContractOutput: ApiContractOutput): ContractOutput {
76
+ const amount: DecodedCompactInt = compactUnsignedIntCodec.fromU256(BigInt(apiContractOutput.attoAlphAmount))
77
+ const lockupScript: P2C = lockupScriptCodec.decode(Buffer.from(bs58.decode(apiContractOutput.address)))
78
+ .script as P2C
79
+
80
+ const tokensValue = apiContractOutput.tokens.map((token) => {
81
+ return {
82
+ tokenId: Buffer.from(token.id, 'hex'),
83
+ amount: compactUnsignedIntCodec.fromU256(BigInt(token.amount))
84
+ }
85
+ })
86
+ const tokens: DecodedArray<Token> = {
87
+ length: compactUnsignedIntCodec.fromU32(tokensValue.length),
88
+ value: tokensValue
89
+ }
90
+
91
+ return { amount, lockupScript, tokens }
92
+ }
93
+ }
94
+
95
+ export const contractOutputCodec = new ContractOutputCodec()
@@ -0,0 +1,42 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ import { Buffer } from 'buffer/'
19
+ import { Parser } from 'binary-parser'
20
+ import { ArrayCodec } from './array-codec'
21
+ import { Codec } from './codec'
22
+ import { signedIntCodec } from './signed-int-codec'
23
+
24
+ export interface ContractOutputRef {
25
+ hint: number
26
+ key: Buffer
27
+ }
28
+
29
+ export class ContractOutputRefCodec implements Codec<ContractOutputRef> {
30
+ parser = Parser.start().int32('hint').buffer('key', { length: 32 })
31
+
32
+ encode(input: ContractOutputRef): Buffer {
33
+ return Buffer.concat([Buffer.from([...signedIntCodec.encode(input.hint), ...input.key])])
34
+ }
35
+
36
+ decode(input: Buffer): ContractOutputRef {
37
+ return this.parser.parse(input)
38
+ }
39
+ }
40
+
41
+ export const contractOutputRefCodec = new ContractOutputRefCodec()
42
+ export const contractOutputRefsCodec = new ArrayCodec(contractOutputRefCodec)
@@ -0,0 +1,74 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ import { Buffer } from 'buffer/'
19
+ import { Parser } from 'binary-parser'
20
+ import { Codec } from './codec'
21
+
22
+ export interface Either<L, R> {
23
+ either: number
24
+ value: L | R
25
+ }
26
+
27
+ export class EitherCodec<L, R> implements Codec<Either<L, R>> {
28
+ constructor(
29
+ private leftCodec: Codec<L>,
30
+ private rightCodec: Codec<R>,
31
+ public parser = Parser.start()
32
+ .uint8('either')
33
+ .choice('value', {
34
+ tag: 'either',
35
+ choices: {
36
+ 0: leftCodec.parser,
37
+ 1: rightCodec.parser
38
+ }
39
+ })
40
+ ) {}
41
+
42
+ encode(input: Either<L, R>): Buffer {
43
+ const result = [input.either]
44
+ if (input.either === 0) {
45
+ result.push(...this.leftCodec.encode(input.value as L))
46
+ } else {
47
+ result.push(...this.rightCodec.encode(input.value as R))
48
+ }
49
+ return Buffer.from(result)
50
+ }
51
+
52
+ decode(input: Buffer): Either<L, R> {
53
+ const result = this.parser.parse(input)
54
+ return {
55
+ ...result,
56
+ value:
57
+ result.either === 0 ? this.leftCodec.decode(result.value.value) : this.rightCodec.decode(result.value.value)
58
+ }
59
+ }
60
+
61
+ fromLeft(left: L): Either<L, R> {
62
+ return {
63
+ either: 0,
64
+ value: left
65
+ }
66
+ }
67
+
68
+ fromRight(right: R): Either<L, R> {
69
+ return {
70
+ either: 1,
71
+ value: right
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ import { Buffer } from 'buffer/'
19
+ import blake from 'blakejs'
20
+
21
+ export function blakeHash(raw: Uint8Array) {
22
+ return blake.blake2b(raw, undefined, 32)
23
+ }
24
+
25
+ export function djbIntHash(bytes: Buffer): number {
26
+ let hash = 5381
27
+ bytes.forEach((byte) => {
28
+ hash = (hash << 5) + hash + (byte & 0xff)
29
+ })
30
+ return hash
31
+ }
32
+
33
+ export function createHint(input: Buffer): number {
34
+ return djbIntHash(input) | 1
35
+ }
@@ -0,0 +1,41 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ export * from './array-codec'
20
+ export * as assetOutput from './asset-output-codec'
21
+ export * from './bigint-codec'
22
+ export * from './bytestring-codec'
23
+ export * from './codec'
24
+ export * from './compact-int-codec'
25
+ export * as contractOutput from './contract-output-codec'
26
+ export * from './contract-output-ref-codec'
27
+ export * from './either-codec'
28
+ export * from './input-codec'
29
+ export * from './instr-codec'
30
+ export * as lockupScript from './lockup-script-codec'
31
+ export * as unlockScript from './unlock-script-codec'
32
+ export * from './long-codec'
33
+ export * from './method-codec'
34
+ export * from './option-codec'
35
+ export * as script from './script-codec'
36
+ export * from './signature-codec'
37
+ export * from './signed-int-codec'
38
+ export * as token from './token-codec'
39
+ export * from './transaction-codec'
40
+ export * from './unsigned-tx-codec'
41
+ export * as contract from './contract-codec'
@@ -0,0 +1,81 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ import { Buffer } from 'buffer/'
19
+ import { Parser } from 'binary-parser'
20
+ import { AssetInput } from '../api/api-alephium'
21
+ import { binToHex } from '../utils'
22
+ import { UnlockScript, unlockScriptCodec } from './unlock-script-codec'
23
+ import { Codec } from './codec'
24
+ import { signedIntCodec } from './signed-int-codec'
25
+ import { ArrayCodec } from './array-codec'
26
+
27
+ export interface Input {
28
+ outputRef: {
29
+ hint: number
30
+ key: Buffer
31
+ }
32
+ unlockScript: UnlockScript
33
+ }
34
+
35
+ export class InputCodec implements Codec<Input> {
36
+ parser = Parser.start()
37
+ .nest('outputRef', {
38
+ type: Parser.start().int32('hint').buffer('key', { length: 32 })
39
+ })
40
+ .nest('unlockScript', {
41
+ type: unlockScriptCodec.parser
42
+ })
43
+
44
+ encode(input: Input): Buffer {
45
+ return Buffer.concat([
46
+ Buffer.from([...signedIntCodec.encode(input.outputRef.hint), ...input.outputRef.key]),
47
+ unlockScriptCodec.encode(input.unlockScript)
48
+ ])
49
+ }
50
+
51
+ decode(input: Buffer): Input {
52
+ return this.parser.parse(input)
53
+ }
54
+
55
+ static toAssetInputs(inputs: Input[]): AssetInput[] {
56
+ return inputs.map((input) => {
57
+ const hint = input.outputRef.hint
58
+ const key = binToHex(input.outputRef.key)
59
+ const unlockScript = unlockScriptCodec.encode(input.unlockScript)
60
+ return {
61
+ outputRef: { hint, key },
62
+ unlockScript: unlockScript.toString('hex')
63
+ }
64
+ })
65
+ }
66
+
67
+ static fromAssetInputs(inputs: AssetInput[]): Input[] {
68
+ return inputs.map((input) => {
69
+ const hint = input.outputRef.hint
70
+ const key = Buffer.from(input.outputRef.key, 'hex')
71
+ const unlockScript = unlockScriptCodec.decode(Buffer.from(input.unlockScript, 'hex'))
72
+ return {
73
+ outputRef: { hint, key },
74
+ unlockScript
75
+ }
76
+ })
77
+ }
78
+ }
79
+
80
+ export const inputCodec = new InputCodec()
81
+ export const inputsCodec = new ArrayCodec(inputCodec)