@anchor-lang/core 1.0.0-rc.2 → 1.0.0-rc.3
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 +1 -1
- package/dist/browser/index.js +121 -26
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/src/idl.d.ts +23 -7
- package/dist/browser/src/idl.d.ts.map +1 -1
- package/dist/browser/src/index.d.ts +1 -1
- package/dist/browser/src/index.d.ts.map +1 -1
- package/dist/browser/src/program/index.d.ts +2 -2
- package/dist/browser/src/program/index.d.ts.map +1 -1
- package/dist/browser/src/provider.d.ts.map +1 -1
- package/dist/browser/src/utils/pubkey.d.ts.map +1 -1
- package/dist/cjs/idl.d.ts +23 -7
- package/dist/cjs/idl.d.ts.map +1 -1
- package/dist/cjs/idl.js +111 -40
- package/dist/cjs/idl.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/program/index.d.ts +2 -2
- package/dist/cjs/program/index.d.ts.map +1 -1
- package/dist/cjs/program/index.js +8 -14
- package/dist/cjs/program/index.js.map +1 -1
- package/dist/cjs/provider.d.ts.map +1 -1
- package/dist/cjs/provider.js +4 -1
- package/dist/cjs/provider.js.map +1 -1
- package/dist/cjs/utils/pubkey.d.ts.map +1 -1
- package/dist/cjs/utils/pubkey.js +2 -3
- package/dist/cjs/utils/pubkey.js.map +1 -1
- package/dist/esm/idl.d.ts +23 -7
- package/dist/esm/idl.d.ts.map +1 -1
- package/dist/esm/idl.js +108 -16
- package/dist/esm/idl.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/program/index.d.ts +2 -2
- package/dist/esm/program/index.d.ts.map +1 -1
- package/dist/esm/program/index.js +6 -12
- package/dist/esm/program/index.js.map +1 -1
- package/dist/esm/provider.d.ts.map +1 -1
- package/dist/esm/provider.js +4 -1
- package/dist/esm/provider.js.map +1 -1
- package/dist/esm/utils/pubkey.d.ts.map +1 -1
- package/dist/esm/utils/pubkey.js +0 -1
- package/dist/esm/utils/pubkey.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @anchor-lang/core
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@anchor-lang/core)
|
|
4
|
-
[](https://
|
|
4
|
+
[](https://solana-foundation.github.io/anchor/ts/index.html)
|
|
5
5
|
|
|
6
6
|
TypeScript client for Anchor programs.
|
|
7
7
|
|
package/dist/browser/index.js
CHANGED
|
@@ -5,10 +5,10 @@ import * as web3_js from '@solana/web3.js';
|
|
|
5
5
|
export { web3_js as web3 };
|
|
6
6
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
7
7
|
import bs58$1 from 'bs58';
|
|
8
|
+
import { inflate, ungzip } from 'pako';
|
|
8
9
|
import camelCase from 'camelcase';
|
|
9
10
|
import * as borsh from '@anchor-lang/borsh';
|
|
10
11
|
import { sha256 as sha256$1 } from '@noble/hashes/sha256';
|
|
11
|
-
import { inflate } from 'pako';
|
|
12
12
|
import EventEmitter from 'eventemitter3';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -108,21 +108,117 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
108
108
|
function isCompositeAccounts(accountItem) {
|
|
109
109
|
return "accounts" in accountItem;
|
|
110
110
|
}
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
// Account format defined at
|
|
112
|
+
// https://github.com/solana-program/program-metadata/blob/734e947d/clients/js/src/generated/accounts/metadata.ts#L123-L138
|
|
113
|
+
const PROGRAM_METADATA_PROGRAM_ID = new PublicKey("ProgM6JCCvbYkfKqJYHePx4xxSUSqJp7rh8Lyv7nk7S");
|
|
114
|
+
const IDL_METADATA_SEED = "idl";
|
|
115
|
+
const ACCOUNT_DISCRIMINATOR_METADATA = 2;
|
|
116
|
+
const DATA_SOURCE_DIRECT = 0;
|
|
117
|
+
// Only JSON formatted data is currently supported
|
|
118
|
+
const FORMAT_JSON = 1;
|
|
119
|
+
const SEED_SIZE = 16;
|
|
120
|
+
const DATA_LENGTH_SIZE = 4;
|
|
121
|
+
const DATA_LENGTH_PADDING = 5;
|
|
122
|
+
const ZEROABLE_OPTION_PUBKEY_SIZE = 32;
|
|
123
|
+
const METADATA_HEADER_SIZE = 1 + 32 + ZEROABLE_OPTION_PUBKEY_SIZE + 1 + 1 + SEED_SIZE + 1 + 1 + 1 + 1;
|
|
124
|
+
var MetadataCompression;
|
|
125
|
+
(function (MetadataCompression) {
|
|
126
|
+
MetadataCompression[MetadataCompression["None"] = 0] = "None";
|
|
127
|
+
MetadataCompression[MetadataCompression["Gzip"] = 1] = "Gzip";
|
|
128
|
+
MetadataCompression[MetadataCompression["Zlib"] = 2] = "Zlib";
|
|
129
|
+
})(MetadataCompression || (MetadataCompression = {}));
|
|
130
|
+
var MetadataEncoding;
|
|
131
|
+
(function (MetadataEncoding) {
|
|
132
|
+
MetadataEncoding[MetadataEncoding["None"] = 0] = "None";
|
|
133
|
+
MetadataEncoding[MetadataEncoding["Utf8"] = 1] = "Utf8";
|
|
134
|
+
MetadataEncoding[MetadataEncoding["Base58"] = 2] = "Base58";
|
|
135
|
+
MetadataEncoding[MetadataEncoding["Base64"] = 3] = "Base64";
|
|
136
|
+
})(MetadataEncoding || (MetadataEncoding = {}));
|
|
137
|
+
function encodeMetadataSeed(seed) {
|
|
138
|
+
const encodedSeed = Buffer$1.from(encode$2(seed));
|
|
139
|
+
if (encodedSeed.length > SEED_SIZE) {
|
|
140
|
+
throw new Error(`Metadata seed '${seed}' exceeds ${SEED_SIZE} bytes`);
|
|
141
|
+
}
|
|
142
|
+
const paddedSeed = Buffer$1.alloc(SEED_SIZE);
|
|
143
|
+
encodedSeed.copy(paddedSeed);
|
|
144
|
+
return paddedSeed;
|
|
145
|
+
}
|
|
146
|
+
function idlAddress(programId) {
|
|
147
|
+
// Canonical metadata uses a null authority seed, which is serialized as `[]`.
|
|
148
|
+
return PublicKey.findProgramAddressSync([
|
|
149
|
+
programId.toBuffer(),
|
|
150
|
+
Buffer$1.alloc(0),
|
|
151
|
+
encodeMetadataSeed(IDL_METADATA_SEED),
|
|
152
|
+
], PROGRAM_METADATA_PROGRAM_ID)[0];
|
|
115
153
|
}
|
|
116
|
-
// Seed for generating the idlAddress.
|
|
117
154
|
function seed() {
|
|
118
|
-
return "
|
|
155
|
+
return "idl";
|
|
119
156
|
}
|
|
120
|
-
const IDL_ACCOUNT_LAYOUT = borsh.struct([
|
|
121
|
-
borsh.publicKey("authority"),
|
|
122
|
-
borsh.vecU8("data"),
|
|
123
|
-
]);
|
|
124
157
|
function decodeIdlAccount(data) {
|
|
125
|
-
|
|
158
|
+
const minimumSize = METADATA_HEADER_SIZE + DATA_LENGTH_SIZE + DATA_LENGTH_PADDING;
|
|
159
|
+
if (data.length < minimumSize) {
|
|
160
|
+
throw new Error("Metadata account is too small");
|
|
161
|
+
}
|
|
162
|
+
let offset = 0;
|
|
163
|
+
const discriminator = data.readUInt8(offset);
|
|
164
|
+
offset += 1;
|
|
165
|
+
if (discriminator !== ACCOUNT_DISCRIMINATOR_METADATA) {
|
|
166
|
+
throw new Error(`Invalid metadata account discriminator: ${discriminator.toString()}`);
|
|
167
|
+
}
|
|
168
|
+
offset += 32; // program
|
|
169
|
+
offset += ZEROABLE_OPTION_PUBKEY_SIZE; // authority
|
|
170
|
+
offset += 1; // mutable
|
|
171
|
+
offset += 1; // canonical
|
|
172
|
+
offset += SEED_SIZE; // seed
|
|
173
|
+
const encoding = data.readUInt8(offset);
|
|
174
|
+
offset += 1;
|
|
175
|
+
const compression = data.readUInt8(offset);
|
|
176
|
+
offset += 1;
|
|
177
|
+
const format = data.readUInt8(offset);
|
|
178
|
+
if (format !== FORMAT_JSON) {
|
|
179
|
+
throw new Error(`IDL has data format '${format}', only JSON IDLs (${FORMAT_JSON}) are supported`);
|
|
180
|
+
}
|
|
181
|
+
offset += 1;
|
|
182
|
+
const dataSource = data.readUInt8(offset);
|
|
183
|
+
if (dataSource !== DATA_SOURCE_DIRECT) {
|
|
184
|
+
throw new Error(`IDL has source '${dataSource}', only directly embedded data (${DATA_SOURCE_DIRECT}) is supported`);
|
|
185
|
+
}
|
|
186
|
+
offset += 1;
|
|
187
|
+
const dataLength = data.readUInt32LE(offset);
|
|
188
|
+
offset += DATA_LENGTH_SIZE + DATA_LENGTH_PADDING;
|
|
189
|
+
if (data.length < offset + dataLength) {
|
|
190
|
+
throw new Error("Metadata account data is truncated");
|
|
191
|
+
}
|
|
192
|
+
const blob = data.subarray(offset, offset + dataLength);
|
|
193
|
+
const decoded = decodeMetadataData(uncompressMetadataData(blob, compression), encoding);
|
|
194
|
+
return JSON.parse(decoded);
|
|
195
|
+
}
|
|
196
|
+
function uncompressMetadataData(data, compression) {
|
|
197
|
+
switch (compression) {
|
|
198
|
+
case MetadataCompression.None:
|
|
199
|
+
return data;
|
|
200
|
+
case MetadataCompression.Gzip:
|
|
201
|
+
return Buffer$1.from(ungzip(data));
|
|
202
|
+
case MetadataCompression.Zlib:
|
|
203
|
+
return Buffer$1.from(inflate(data));
|
|
204
|
+
default:
|
|
205
|
+
throw new Error(`Unsupported metadata compression: ${String(compression)}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function decodeMetadataData(data, encoding) {
|
|
209
|
+
switch (encoding) {
|
|
210
|
+
// 'None' is actually hex-encoded
|
|
211
|
+
case MetadataEncoding.None:
|
|
212
|
+
return data.toString("hex");
|
|
213
|
+
case MetadataEncoding.Utf8:
|
|
214
|
+
return decode$2(data);
|
|
215
|
+
case MetadataEncoding.Base58:
|
|
216
|
+
return encode$1(data);
|
|
217
|
+
case MetadataEncoding.Base64:
|
|
218
|
+
return data.toString("base64");
|
|
219
|
+
default:
|
|
220
|
+
throw new Error(`Unsupported metadata encoding: ${String(encoding)}`);
|
|
221
|
+
}
|
|
126
222
|
}
|
|
127
223
|
/**
|
|
128
224
|
* Convert the given IDL to camelCase.
|
|
@@ -1027,7 +1123,10 @@ class AnchorProvider {
|
|
|
1027
1123
|
}
|
|
1028
1124
|
else {
|
|
1029
1125
|
tx.feePayer = (_a = tx.feePayer) !== null && _a !== void 0 ? _a : this.wallet.publicKey;
|
|
1030
|
-
tx.recentBlockhash
|
|
1126
|
+
if (!tx.recentBlockhash ||
|
|
1127
|
+
tx.recentBlockhash === "11111111111111111111111111111111") {
|
|
1128
|
+
tx.recentBlockhash = (await this.connection.getLatestBlockhash(opts.preflightCommitment)).blockhash;
|
|
1129
|
+
}
|
|
1031
1130
|
if (signers) {
|
|
1032
1131
|
for (const signer of signers) {
|
|
1033
1132
|
tx.partialSign(signer);
|
|
@@ -4525,9 +4624,9 @@ var sha256 = /*#__PURE__*/Object.freeze({
|
|
|
4525
4624
|
|
|
4526
4625
|
// Sync version of web3.PublicKey.createWithSeed.
|
|
4527
4626
|
function createWithSeedSync(fromPublicKey, seed, programId) {
|
|
4528
|
-
const buffer = Buffer
|
|
4627
|
+
const buffer = Buffer.concat([
|
|
4529
4628
|
fromPublicKey.toBuffer(),
|
|
4530
|
-
Buffer
|
|
4629
|
+
Buffer.from(seed),
|
|
4531
4630
|
programId.toBuffer(),
|
|
4532
4631
|
]);
|
|
4533
4632
|
return new PublicKey(sha256$1(buffer));
|
|
@@ -6693,7 +6792,7 @@ class NamespaceFactory {
|
|
|
6693
6792
|
*
|
|
6694
6793
|
* API specifics are namespace dependent. The examples used in the documentation
|
|
6695
6794
|
* below will refer to the two counter examples found
|
|
6696
|
-
* [here](https://github.com/
|
|
6795
|
+
* [here](https://github.com/solana-foundation/anchor#examples).
|
|
6697
6796
|
*/
|
|
6698
6797
|
class Program {
|
|
6699
6798
|
/**
|
|
@@ -6782,18 +6881,14 @@ class Program {
|
|
|
6782
6881
|
* @param programId The on-chain address of the program.
|
|
6783
6882
|
* @param provider The network and wallet context.
|
|
6784
6883
|
*/
|
|
6785
|
-
static async fetchIdl(
|
|
6884
|
+
static async fetchIdl(programAddress, provider) {
|
|
6786
6885
|
provider = provider !== null && provider !== void 0 ? provider : getProvider();
|
|
6787
|
-
const programId = translateAddress(
|
|
6788
|
-
const idlAddr =
|
|
6886
|
+
const programId = translateAddress(programAddress);
|
|
6887
|
+
const idlAddr = idlAddress(programId);
|
|
6789
6888
|
const accountInfo = await provider.connection.getAccountInfo(idlAddr);
|
|
6790
|
-
if (!accountInfo)
|
|
6889
|
+
if (!accountInfo)
|
|
6791
6890
|
return null;
|
|
6792
|
-
|
|
6793
|
-
// Chop off account discriminator.
|
|
6794
|
-
let idlAccount = decodeIdlAccount(accountInfo.data.slice(8));
|
|
6795
|
-
const inflatedIdl = inflate(idlAccount.data);
|
|
6796
|
-
return JSON.parse(decode$2(inflatedIdl));
|
|
6891
|
+
return decodeIdlAccount(accountInfo.data);
|
|
6797
6892
|
}
|
|
6798
6893
|
/**
|
|
6799
6894
|
* Invokes the given callback every time the given event is emitted.
|
|
@@ -7205,5 +7300,5 @@ class Native {
|
|
|
7205
7300
|
}
|
|
7206
7301
|
}
|
|
7207
7302
|
|
|
7208
|
-
export { AccountClient, AnchorError, AnchorProvider, BorshAccountsCoder, BorshCoder, BorshEventCoder, BorshInstructionCoder, EventManager, EventParser, IdlError, LangErrorCode, LangErrorMessage, MethodsBuilderFactory, Native, Program, ProgramError, ProgramErrorStack, SystemCoder, getProvider, parseIdlErrors, setProvider, splitArgsAndCtx, toInstruction, translateAddress, translateError, index as utils, validateAccounts };
|
|
7303
|
+
export { AccountClient, AnchorError, AnchorProvider, BorshAccountsCoder, BorshCoder, BorshEventCoder, BorshInstructionCoder, EventManager, EventParser, FORMAT_JSON, IdlError, LangErrorCode, LangErrorMessage, MetadataCompression, MetadataEncoding, MethodsBuilderFactory, Native, Program, ProgramError, ProgramErrorStack, SystemCoder, convertIdlToCamelCase, decodeIdlAccount, decodeMetadataData, getProvider, handleDefinedFields, idlAddress, isCompositeAccounts, parseIdlErrors, seed, setProvider, splitArgsAndCtx, toInstruction, translateAddress, translateError, uncompressMetadataData, index as utils, validateAccounts };
|
|
7209
7304
|
//# sourceMappingURL=index.js.map
|