@intent-engine/core 0.1.27 → 0.1.28
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/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/profile.d.ts +30 -0
- package/dist/src/profile.js +71 -0
- package/dist/src/profile.js.map +1 -0
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Address, type ReadonlyUint8Array, type TransactionSigner } from "@solana/kit";
|
|
2
|
+
export declare const PROFILE_MAX_SKILLS = 8;
|
|
3
|
+
export declare const PROFILE_SKILL_LEN = 16;
|
|
4
|
+
export declare const PROFILE_MAX_URL_LEN = 128;
|
|
5
|
+
export type ProfileInput = {
|
|
6
|
+
skills: string[];
|
|
7
|
+
endpoint: string;
|
|
8
|
+
docUrl?: string;
|
|
9
|
+
docSha256?: string;
|
|
10
|
+
};
|
|
11
|
+
export type ProfileView = {
|
|
12
|
+
wallet: Address;
|
|
13
|
+
skills: string[];
|
|
14
|
+
endpoint: string;
|
|
15
|
+
docUrl: string | null;
|
|
16
|
+
docSha256: string | null;
|
|
17
|
+
updatedAt: bigint;
|
|
18
|
+
};
|
|
19
|
+
export declare function checkProfile(input: ProfileInput): ProfileInput;
|
|
20
|
+
export declare function profileAddress(wallet: Address): Promise<Address>;
|
|
21
|
+
export declare function buildCreateProfile(input: {
|
|
22
|
+
wallet: TransactionSigner;
|
|
23
|
+
} & ProfileInput): Promise<import("../generated/client/index.js").CreateProfileInstruction<Address<"GHFB9q4fhhqRyCoycoivdxMhFkp1aLHJk5VvroUsgrJU">, string, string, string, string, "GHFB9q4fhhqRyCoycoivdxMhFkp1aLHJk5VvroUsgrJU", []>>;
|
|
24
|
+
export declare function buildUpdateProfile(input: {
|
|
25
|
+
wallet: TransactionSigner;
|
|
26
|
+
} & ProfileInput): Promise<import("../generated/client/index.js").UpdateProfileInstruction<Address<"GHFB9q4fhhqRyCoycoivdxMhFkp1aLHJk5VvroUsgrJU">, string, string, string, "GHFB9q4fhhqRyCoycoivdxMhFkp1aLHJk5VvroUsgrJU", []>>;
|
|
27
|
+
export declare function buildCloseProfile(input: {
|
|
28
|
+
wallet: TransactionSigner;
|
|
29
|
+
}): Promise<import("../generated/client/index.js").CloseProfileInstruction<Address<"GHFB9q4fhhqRyCoycoivdxMhFkp1aLHJk5VvroUsgrJU">, string, string, string, "GHFB9q4fhhqRyCoycoivdxMhFkp1aLHJk5VvroUsgrJU", []>>;
|
|
30
|
+
export declare function profileView(data: ReadonlyUint8Array): ProfileView;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { getBase16Decoder, getBase16Encoder } from "@solana/kit";
|
|
2
|
+
import { findProfilePda, getCloseProfileInstructionAsync, getCreateProfileInstructionAsync, getProfileDecoder, getProfileSize, getUpdateProfileInstructionAsync, PROFILE_DISCRIMINATOR, } from "../generated/client/index.js";
|
|
3
|
+
import { events } from "./builder-accounts.js";
|
|
4
|
+
import { IntentCoreError } from "./errors.js";
|
|
5
|
+
export const PROFILE_MAX_SKILLS = 8;
|
|
6
|
+
export const PROFILE_SKILL_LEN = 16;
|
|
7
|
+
export const PROFILE_MAX_URL_LEN = 128;
|
|
8
|
+
const SKILL = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
|
|
9
|
+
const URL_BODY = /^https:\/\/[\x21-\x5b\x5d-\x7e]+$/;
|
|
10
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
11
|
+
const ZERO_HASH = "0".repeat(64);
|
|
12
|
+
const validUrl = (text) => text.length <= PROFILE_MAX_URL_LEN && URL_BODY.test(text);
|
|
13
|
+
export function checkProfile(input) {
|
|
14
|
+
const { skills, endpoint, docUrl, docSha256 } = input;
|
|
15
|
+
const hash = docSha256?.toLowerCase();
|
|
16
|
+
const skillsValid = skills.length >= 1 &&
|
|
17
|
+
skills.length <= PROFILE_MAX_SKILLS &&
|
|
18
|
+
new Set(skills).size === skills.length &&
|
|
19
|
+
skills.every((s) => s.length <= PROFILE_SKILL_LEN && SKILL.test(s));
|
|
20
|
+
const docValid = (docUrl === undefined) === (hash === undefined) &&
|
|
21
|
+
(docUrl === undefined || validUrl(docUrl)) &&
|
|
22
|
+
(hash === undefined || (SHA256.test(hash) && hash !== ZERO_HASH));
|
|
23
|
+
if (!skillsValid || !validUrl(endpoint) || !docValid) {
|
|
24
|
+
throw new IntentCoreError("ProfileInvalid");
|
|
25
|
+
}
|
|
26
|
+
return { skills: [...skills], endpoint, ...(docUrl === undefined || hash === undefined ? {} : { docUrl, docSha256: hash }) };
|
|
27
|
+
}
|
|
28
|
+
function fieldsOf(input) {
|
|
29
|
+
const checked = checkProfile(input);
|
|
30
|
+
return {
|
|
31
|
+
skills: checked.skills,
|
|
32
|
+
endpoint: checked.endpoint,
|
|
33
|
+
docUrl: checked.docUrl ?? "",
|
|
34
|
+
docHash: checked.docSha256 === undefined ? new Uint8Array(32) : getBase16Encoder().encode(checked.docSha256),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export async function profileAddress(wallet) {
|
|
38
|
+
return (await findProfilePda({ wallet }))[0];
|
|
39
|
+
}
|
|
40
|
+
export async function buildCreateProfile(input) {
|
|
41
|
+
const args = fieldsOf(input);
|
|
42
|
+
return getCreateProfileInstructionAsync({ wallet: input.wallet, args, ...(await events()) });
|
|
43
|
+
}
|
|
44
|
+
export async function buildUpdateProfile(input) {
|
|
45
|
+
const args = fieldsOf(input);
|
|
46
|
+
return getUpdateProfileInstructionAsync({ wallet: input.wallet, args, ...(await events()) });
|
|
47
|
+
}
|
|
48
|
+
export async function buildCloseProfile(input) {
|
|
49
|
+
return getCloseProfileInstructionAsync({ wallet: input.wallet, ...(await events()) });
|
|
50
|
+
}
|
|
51
|
+
const ascii = (bytes) => {
|
|
52
|
+
const end = bytes.indexOf(0);
|
|
53
|
+
return new TextDecoder().decode(bytes.slice(0, end < 0 ? bytes.length : end));
|
|
54
|
+
};
|
|
55
|
+
export function profileView(data) {
|
|
56
|
+
if (data.length < getProfileSize() || !PROFILE_DISCRIMINATOR.every((b, i) => data[i] === b)) {
|
|
57
|
+
throw new RangeError("the data is not a profile account");
|
|
58
|
+
}
|
|
59
|
+
const stored = getProfileDecoder().decode(data);
|
|
60
|
+
const docUrl = ascii(stored.docUrl);
|
|
61
|
+
const docSha256 = getBase16Decoder().decode(stored.docHash).toLowerCase();
|
|
62
|
+
return {
|
|
63
|
+
wallet: stored.wallet,
|
|
64
|
+
skills: stored.skills.map(ascii).filter((s) => s !== ""),
|
|
65
|
+
endpoint: ascii(stored.endpoint),
|
|
66
|
+
docUrl: docUrl === "" ? null : docUrl,
|
|
67
|
+
docSha256: docSha256 === ZERO_HASH ? null : docSha256,
|
|
68
|
+
updatedAt: stored.updatedAt,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAE,gBAAgB,EAAmD,MAAM,aAAa,CAAC;AAChI,OAAO,EACL,cAAc,EACd,+BAA+B,EAC/B,gCAAgC,EAChC,iBAAiB,EACjB,cAAc,EACd,gCAAgC,EAChC,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MA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