MCPcopy Create free account
hub / github.com/aurora-develop/Duck2api / executeVQDHashScript

Function executeVQDHashScript

internal/duckgo/vqd.go:51–86  ·  view source on GitHub ↗
(jsCode string)

Source from the content-addressed store, hash-verified

49}
50
51func executeVQDHashScript(jsCode string) (string, error) {
52 vm := goja.New()
53 if err := installVQDHelpers(vm); err != nil {
54 return "", err
55 }
56 if _, err := vm.RunString(vqdBrowserPrelude); err != nil {
57 return "", fmt.Errorf("initialize vqd browser mock: %w", err)
58 }
59
60 value, err := vm.RunString(jsCode)
61 if err != nil {
62 return "", fmt.Errorf("execute vqd hash script: %s", jsErrorString(vm, err, nil))
63 }
64
65 if promise, ok := value.Export().(*goja.Promise); ok {
66 switch promise.State() {
67 case goja.PromiseStateFulfilled:
68 value = promise.Result()
69 case goja.PromiseStateRejected:
70 return "", fmt.Errorf("vqd hash script rejected: %s", jsErrorString(vm, nil, promise.Result()))
71 default:
72 return "", errors.New("vqd hash script did not resolve")
73 }
74 }
75
76 vm.Set("__vqd_result", value)
77 payload, err := vm.RunString(vqdResultMutationScript)
78 if err != nil {
79 return "", fmt.Errorf("encode vqd hash result: %s", jsErrorString(vm, err, nil))
80 }
81 if goja.IsUndefined(payload) || goja.IsNull(payload) {
82 return "", errors.New("vqd hash script returned an empty result")
83 }
84
85 return payload.String(), nil
86}
87
88func installVQDHelpers(vm *goja.Runtime) error {
89 if err := vm.Set("__goVQDUserAgent", vqdUserAgent()); err != nil {

Callers 1

GenerateVQDHashFunction · 0.85

Calls 4

installVQDHelpersFunction · 0.85
jsErrorStringFunction · 0.85
SetMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected