@effected/github 0.3.0 → 0.4.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.
package/index.js CHANGED
@@ -6,6 +6,8 @@ import { InvalidRepoRefError, Repo, RepoRef } from "./Repo.js";
6
6
  import { ArtifactMetadata, StorageRecordInput } from "./ArtifactMetadata.js";
7
7
  import { Attestation, AttestationListEntry, AttestationRecord } from "./Attestation.js";
8
8
  import { Annotation, AnnotationLevel, CheckConclusion, CheckRun, CheckRunOutput, CheckRunRef } from "./CheckRun.js";
9
+ import { CodeScanning } from "./CodeScanning.js";
10
+ import { DeploymentEnvironment } from "./DeploymentEnvironment.js";
9
11
  import { GitBranch } from "./GitBranch.js";
10
12
  import { CommitRef, FileChange, FileContent, FileDeletion, FileMode, GitCommit } from "./GitCommit.js";
11
13
  import { AppIdentity, BotIdentity, GitHubApp, GitHubAppError, Installation, InstallationToken } from "./GitHubApp.js";
@@ -13,12 +15,16 @@ import { CommitComparison, CommitFile, CommitSummary, FileStatus, GitHubCommit }
13
15
  import { GitHubContent } from "./GitHubContent.js";
14
16
  import { GitHubIssue, IssueInfo, LinkedIssue } from "./GitHubIssue.js";
15
17
  import { GitHubRelease, ReleaseAsset, ReleaseInfo } from "./GitHubRelease.js";
16
- import { GitHubRepository } from "./GitHubRepository.js";
18
+ import { GRAPHQL_ONLY_SETTINGS, GitHubRepository, SECURITY_ANALYSIS_STATUS_FIELDS, transformSecurityAndAnalysis } from "./GitHubRepository.js";
17
19
  import { GitTag, SemverTag, TagRef, versionFromTag } from "./GitTag.js";
18
20
  import { PageOptions } from "./Rest.js";
19
21
  import { MergeMethod, PullRequest, PullRequestInfo } from "./PullRequest.js";
20
22
  import { CommentMarker, CommentRecord, PullRequestComment } from "./PullRequestComment.js";
23
+ import { RepositorySecret } from "./RepositorySecret.js";
24
+ import { RepositorySecurity } from "./RepositorySecurity.js";
25
+ import { RepositoryVariable } from "./RepositoryVariable.js";
26
+ import { Ruleset } from "./Ruleset.js";
21
27
  import { ExtraPermission, PermissionGap, PermissionLevel, PermissionResult, TokenPermissionError, TokenPermissions } from "./TokenPermissions.js";
22
28
  import { WorkflowDispatch, WorkflowRunStatus } from "./WorkflowDispatch.js";
23
29
 
24
- export { Annotation, AnnotationLevel, AppIdentity, ArtifactMetadata, Attestation, AttestationListEntry, AttestationRecord, BotIdentity, CheckConclusion, CheckRun, CheckRunOutput, CheckRunRef, CommentMarker, CommentRecord, CommitComparison, CommitFile, CommitRef, CommitSummary, ExtraPermission, FileChange, FileContent, FileDeletion, FileMode, FileStatus, GitBranch, GitCommit, GitHubApp, GitHubAppError, GitHubClient, GitHubCommit, GitHubContent, GitHubError, GitHubErrorKind, GitHubGraphQLError, GitHubIssue, GitHubRelease, GitHubRepository, GitTag, GraphQLDocument, GraphQLErrorEntry, Installation, InstallationToken, InvalidRepoRefError, IssueInfo, LinkedIssue, MergeMethod, PageOptions, PermissionGap, PermissionLevel, PermissionResult, PullRequest, PullRequestComment, PullRequestInfo, RateLimitSnapshot, ReleaseAsset, ReleaseInfo, Repo, RepoRef, RetryPolicy, SemverTag, StorageRecordInput, TagRef, TokenPermissionError, TokenPermissions, WorkflowDispatch, WorkflowRunStatus, versionFromTag };
30
+ export { Annotation, AnnotationLevel, AppIdentity, ArtifactMetadata, Attestation, AttestationListEntry, AttestationRecord, BotIdentity, CheckConclusion, CheckRun, CheckRunOutput, CheckRunRef, CodeScanning, CommentMarker, CommentRecord, CommitComparison, CommitFile, CommitRef, CommitSummary, DeploymentEnvironment, ExtraPermission, FileChange, FileContent, FileDeletion, FileMode, FileStatus, GRAPHQL_ONLY_SETTINGS, GitBranch, GitCommit, GitHubApp, GitHubAppError, GitHubClient, GitHubCommit, GitHubContent, GitHubError, GitHubErrorKind, GitHubGraphQLError, GitHubIssue, GitHubRelease, GitHubRepository, GitTag, GraphQLDocument, GraphQLErrorEntry, Installation, InstallationToken, InvalidRepoRefError, IssueInfo, LinkedIssue, MergeMethod, PageOptions, PermissionGap, PermissionLevel, PermissionResult, PullRequest, PullRequestComment, PullRequestInfo, RateLimitSnapshot, ReleaseAsset, ReleaseInfo, Repo, RepoRef, RepositorySecret, RepositorySecurity, RepositoryVariable, RetryPolicy, Ruleset, SECURITY_ANALYSIS_STATUS_FIELDS, SemverTag, StorageRecordInput, TagRef, TokenPermissionError, TokenPermissions, WorkflowDispatch, WorkflowRunStatus, transformSecurityAndAnalysis, versionFromTag };
@@ -0,0 +1,63 @@
1
+ import { Encoding, Result } from "effect";
2
+ import blakejs from "blakejs";
3
+ import nacl from "tweetnacl";
4
+
5
+ //#region src/internal/crypto.ts
6
+ const { blake2b } = blakejs;
7
+ /** A sealed box opens with the recipient's key; the nonce is derived, not sent. */
8
+ const NONCE_BYTES = 24;
9
+ const PUBLIC_KEY_BYTES = 32;
10
+ const utf8 = new TextEncoder();
11
+ /**
12
+ * Encrypt a secret with libsodium's sealed-box algorithm, the format GitHub's
13
+ * secrets API requires.
14
+ *
15
+ * @remarks
16
+ * A sealed box is `ephemeral_public_key (32 bytes) || ciphertext`. The sender
17
+ * mints a throwaway keypair, derives the nonce deterministically from both
18
+ * public keys, encrypts with `crypto_box`, and discards the ephemeral secret
19
+ * key — so nobody, including this process a moment later, can decrypt what it
20
+ * just wrote. Only the holder of `publicKey`'s private half can.
21
+ *
22
+ * The nonce is `blake2b(ephemeral_pk || recipient_pk, 24)`. It is **derived**
23
+ * rather than random because the recipient has to recompute it from the two
24
+ * public keys alone, having received no nonce alongside the box. Both the
25
+ * concatenation order and the 24-byte length are fixed by the libsodium
26
+ * specification — changing either produces a box GitHub accepts and cannot
27
+ * decrypt, which is a silent failure that surfaces as a workflow reading a
28
+ * corrupt secret rather than as an error here.
29
+ *
30
+ * ## Nothing here is Node-specific
31
+ *
32
+ * Base64 goes through core's `Encoding` and text through `TextEncoder`, so this
33
+ * module imports **no builtin**. That is deliberate: an earlier draft used
34
+ * `node:buffer` and was the only thing in this package's reachable graph tying
35
+ * it to a runtime — neither `blakejs` (pure JS; its `util` is a *relative*
36
+ * file) nor `tweetnacl` (which feature-detects `getRandomValues` and falls back
37
+ * to Node's `crypto` only when there is no WebCrypto) locks it.
38
+ *
39
+ * A malformed `publicKey` fails as a typed `Result` rather than throwing:
40
+ * garbage from the API is input, and input failures are typed.
41
+ *
42
+ * @param publicKey - The repository, environment or organization public key,
43
+ * base64, as returned by GitHub's `.../secrets/public-key` endpoints.
44
+ * @param secretValue - The plaintext to seal.
45
+ * @returns The sealed box, base64, ready to send as `encrypted_value`.
46
+ *
47
+ * @internal
48
+ */
49
+ const encryptSecret = (publicKey, secretValue) => Result.map(Encoding.decodeBase64(publicKey), (publicKeyBytes) => {
50
+ const ephemeralKeyPair = nacl.box.keyPair();
51
+ const nonceInput = /* @__PURE__ */ new Uint8Array(64);
52
+ nonceInput.set(ephemeralKeyPair.publicKey);
53
+ nonceInput.set(publicKeyBytes, PUBLIC_KEY_BYTES);
54
+ const nonce = blake2b(nonceInput, void 0, NONCE_BYTES);
55
+ const ciphertext = nacl.box(utf8.encode(secretValue), nonce, publicKeyBytes, ephemeralKeyPair.secretKey);
56
+ const sealed = new Uint8Array(ephemeralKeyPair.publicKey.length + ciphertext.length);
57
+ sealed.set(ephemeralKeyPair.publicKey);
58
+ sealed.set(ciphertext, ephemeralKeyPair.publicKey.length);
59
+ return Encoding.encodeBase64(sealed);
60
+ });
61
+
62
+ //#endregion
63
+ export { encryptSecret };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/github",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "description": "Typed GitHub REST and GraphQL services over the octokit core request surface, with app auth and resource helpers.",
6
6
  "keywords": [
@@ -42,6 +42,8 @@
42
42
  "@octokit/core": "^7.0.6",
43
43
  "@octokit/plugin-paginate-rest": "^14.0.0",
44
44
  "@octokit/types": "^16.0.0",
45
+ "blakejs": "1.2.1",
46
+ "tweetnacl": "1.0.3",
45
47
  "universal-github-app-jwt": "^2.2.2"
46
48
  },
47
49
  "peerDependencies": {